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 Quote Link to comment 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> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.