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?

3
  • 1
    If what you are looking for is a fixed string, just use strpos instead. Commented Apr 14, 2019 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. Commented Apr 14, 2019 at 12:42
  • Simply don't try to parse valid html with regex; use a DOM parser. Commented Apr 14, 2019 at 12:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.