tuxonice Posted November 10, 2009 at 12:05 PM Report Share #295384 Posted November 10, 2009 at 12:05 PM Oi ppl, ando com dificuldade em encontrar um regex para utilizar com a funcção preg_match(), para descobrir URL de imagens dentro de textos, tipo: http://www.site.com/pasta/subpasta/image.jpg'>http://www.site.com/pasta/subpasta/image.jpg tentei vários que encontrei pela net mas nenhum funciona. O ultimo que teste foi este: (((http://www)|(http://)|(www))[-a-zA-Z0-9@:%_\+.~#?&//=]+)\.(jpg|jpeg|gif|png|bmp|tiff|tga|svg) que encontrei neste "tester online" : http://www.gskinner.com/RegExr/ funciona bem nesse site mas não funciona no meu código... Alguma sugestão? Tux Link to comment Share on other sites More sharing options...
infopc Posted November 10, 2009 at 12:42 PM Report Share #295390 Posted November 10, 2009 at 12:42 PM Qual é o erro que te esta a dar? O que não tem solução, solucionado esta... Link to comment Share on other sites More sharing options...
tuxonice Posted November 10, 2009 at 04:31 PM Author Report Share #295445 Posted November 10, 2009 at 04:31 PM O codigo é este: $str = 'Lorem ipsum dolor sit amet, consectetur http://www.example.com/folder/image.jpg Fusce dui sapien, lobortis commodo pharetra eget,'; $pattern = '(((http://www)|(http://)|(www))[-a-zA-Z0-9@:%_\+.~#?&//=]+)\.(jpg|jpeg|gif|png|bmp|tiff|tga|svg)'; preg_match($pattern, $str, $results); print_r($results); e o erro (warning) é este: Warning: preg_match() [function.preg-match]: Unknown modifier '\' in C:\web\testes\teste.php on line 5 APARTE: Usa Geshi, o código fica mais apresentável. Link to comment Share on other sites More sharing options...
yoda Posted November 10, 2009 at 10:19 PM Report Share #295504 Posted November 10, 2009 at 10:19 PM Boas, experimenta assim : $pattern = '(((http://www)|(http://)|(www))[-a-zA-Z0-9@:%_+.~#?&//=]+)\.(jpg|jpeg|gif|png|bmp|tiff|tga|svg)'; O "\" é usado para escapar caracteres. Se não funcionar, experimenta usar o software daqui : http://www.regexbuddy.com/ before you post, what have you tried? - http://filipematias.info sense, purpose, direction Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now