Jump to content

Regex para URL de imagens


tuxonice
 Share

Recommended Posts

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

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

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/

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.