Skip to content Skip to sidebar Skip to footer

Regular Expression To Find "src" Attribute Of Html "img" Element In Php

I have a string, inside of that I have an image: '

' I could not fetc

Solution 1:

I'd catch everything inside the quotes:

preg_match_all('/src="([^"]+)"/', $questArr_str, $images);

Solution 2:

The parts that reads ([^\s]+) means select anything that isn't a space.

Maybe try something like:

/src="([^"]+)"/

Which is select anything that isn't a double quote.

Solution 3:

Thank every one for helping me out.

I found my solution by using:

pattern = "/src=([^\\\"]+)/"

Solution 4:

Here is an easy way to match <img /> tag src attribute and or it content in html/PHP with regular expression.

Sample:

<img class="img img-responsive" title="publisher.PNG" src="media/projectx/agent/author/post/2/image/publisher.PNG" alt="" width="80%" />

To match just src attribute content use

preg_match("%(?<=src=\")([^\"])+(png|jpg|gif)%i",$input,$result)

$result[0] will output media/projectx/agent/author/post/2/image/publisher.PNG To match `src' attribute and it content use

preg_match("%src=\"([^\"])+(png|jpg|gif)\"%i",$input,$result)

$result[0] will output src="media/projectx/agent/author/post/2/image/publisher.PNG"

Post a Comment for "Regular Expression To Find "src" Attribute Of Html "img" Element In Php"