regex - PHP Find a URL in any form within a string -


i'm looking form of input security on project working on. wish flag text if user has inputted form of url.

ie 'for more of pic visit myhotpic.net'

hence detect url , can flag string validation via staff. need check form of url.

there similar question here finding urls text string via php , regex? answer. have tired various strings , not expected results.

for example

$pattern = '#(www\.|https?:\/\/){?}[a-za-z0-9]{2,254}\.[a-za-z0-9]{2,4}(\s*)#i'; $count = preg_match_all($pattern, 'http://www.imaurl.com', $matches, preg_pattern_order);

returns matches as

array(3) {   [0]=>   array(0) {   }   [1]=>   array(0) {   }   [2]=>   array(0) {   } } 

and no error return via preg_last_error()

why not working? there error in regex? assume fine other users have had success it.

i cannot seem find suitable answer problem anywhere else.

in regex, change {?} ?. work. no idea {?} supposed mean (i've never seen that).

your regex work fine some urls, should aware urls can more complicated might assume, , regex can match every url complex. might want better regex—you need 1 complicated enough handle sorts of urls you're expecting match.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -