开发者

php preg_match image address which is bagin as letter

开发者 https://www.devze.com 2023-02-20 19:49 出处:网络
I want to get all the image address which is a letter. I use this... <?php $str = <<<EOT imag开发者_如何学编程e/20110331_121.jpg

I want to get all the image address which is a letter. I use this...

<?php
$str = <<<EOT
imag开发者_如何学编程e/20110331_121.jpg
../image/20110330_132.jpg
http://www.site.com/image/20110330_098.jpg
EOT;
$image = preg_match('#^[a-zA-Z](.*)\/.(jpg)$#i',$str);
print_r($image);// I want get a echo image/20110331_121.jpg
?>


Your problem was the \/ right before the .jpg without any placeholder. You could try this:

 $image = preg_match('#^[a-z]\w+/\w+[.](jpg)$#im',$str);

And you also forgot the #m modifier to apply ^ and $ against multiple lines.

0

精彩评论

暂无评论...
验证码 换一张
取 消