0

I am trying to find the first image from the content. Using Regex

<imgs+((width|height|border|classs|id|src|usemap|hspace|vspace)=”[^"]+”s*)+>

The function is used as

<?php
$content="<img src='s' height='20' >";

preg_match("/<imgs+((width|height|border|classs|id|src|usemap|hspace|vspace)=”[^"]+”s*)+>
/" ,$content,$matches);
var_dump($matches);
?>

But i get a syntax error. I want to handle all possible cases for img tags, how can this be done? I need the src attribute of the tag.

Amna Ahmed
  • 1,944
  • 4
  • 20
  • 25

1 Answers1

0

You won't be able to catch all possible cases with a regex. HTML generally can not be successfully parsed using only regular expression matching - it's just too complex.

You will need to use a proper html parser, or limit yourself to a subset of possible solutions.

Rik Heywood
  • 13,816
  • 9
  • 61
  • 81