preg_match_all question

preg_match_all(‘/(height|width|style|src)=(“[^”\’]*")/i’,$img_tag, $img[$img_tag]);

How would I change this to work with both ’ and " ?

Thanks E

Try:

'?"?

You have to escape (\') only single quotes that you have used to wrap the patterns. Double quotes are treated as they are AFAIK.

But that would allow neither of them to be set?

You can use | to do either " or ':

preg_match_all('/(height|width|style|src)=(("|\\')[^"\\']*("|\\'))/i',$img_tag, $img[$img_tag]);

Edit: If you want the attribute value, the following would be easier:

preg_match_all('/(height|width|style|src)=(?:"|\\')([^"\\']*)(?:"|\\')/i', $img_tag, $img[$img_tag]);