t_machine Posted September 15, 2008 Share Posted September 15, 2008 hi, i am using a tutorial I found that gets the image src, image type but does not show how to get the name itself. example: $data = 'Some text here <img src="images/myimg.jpg" border="0"> more text.'; $pattern = "/src=[\"']?([^\"']?.*(png|jpg|gif))[\"']?/i"; preg_match_all($pattern, $data, $images); echo $images[0][0]; //src=images/myimg.jpg echo $images[1][0]; //images/myimg.jpg echo $images[2][0]; //jpg How can I get "myimg" from the src url? Thanks for any help Link to comment https://forums.phpfreaks.com/topic/124318-solved-how-to-get-image-name-using-preg_match_all/ Share on other sites More sharing options...
effigy Posted September 15, 2008 Share Posted September 15, 2008 <pre> <?php $data = 'Some text here <img src="images/myimg.jpg" border="0"> more text.'; preg_match_all('/src=([\'"])?((?(1).*?|\S+))(?(1)\1)/', $data, $images); foreach ($images[2] as $src) { print_r(pathinfo($src)); } ?> </pre> Link to comment https://forums.phpfreaks.com/topic/124318-solved-how-to-get-image-name-using-preg_match_all/#findComment-641980 Share on other sites More sharing options...
t_machine Posted September 15, 2008 Author Share Posted September 15, 2008 Thanks very much for the reply That is exactly what I needed. Link to comment https://forums.phpfreaks.com/topic/124318-solved-how-to-get-image-name-using-preg_match_all/#findComment-641998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.