0

I need search in html string this code:

 <a href="http://example.com" target="_blank" title="Site name"><img src="http://site.loc/images/banners/we_on.png" width="88" height="31" alt="Site name"></a>

How I can find this with regex?

I tried this:

$html = (string) $client->getBody(); //html content 

$verified = preg_match('/ <a href="http://example.com" target="_blank" 
title="Site name"><img src="http://site.loc/images/banners/we_on.png" 
 width="88" height="31" alt="Site name"></a>
  /', $html) ? true : false;

But I get error undefined expression. Maybe need check if on html I have a link and href of this link?

Mafys Grif
  • 557
  • 3
  • 13
  • 30
  • 1
    If what you are looking for is a fixed string, just use [`strpos`](https://www.php.net/manual/en/function.strpos.php) instead. – Nick Apr 14 '19 at 12:39
  • 1
    There are a bunch of characters in your regex-pattern that would need to be escaped. Many characters have special meanings in regular expressions. But as @Nick already pointed out, no need to use regex at all if you're looking for a fixed string. – M. Eriksson Apr 14 '19 at 12:42
  • Simply don't try to parse valid html with regex; use a DOM parser. – mickmackusa Apr 14 '19 at 12:49

0 Answers0