str_replace无法正常工作

I was experimenting with str_replace but I'm having some problems with this specific line:

$content = str_replace('<div id='demo'><a href='https://www.example.com' target='_blank'><img alt='Demo' src='//example.com/image.png' /></a></div>', '', $content);

I've tried changing the quotes but nothing worked. Thank you for your time.

EDIT: I got it to work by separing the code into two different str_replace.

Try with single and double quotes when you have a string

$content = str_replace('<div id="demo"><a href="https://www.example.com" target="_blank"><img alt="Demo" src="//example.com/image.png" /></a></div>', '', $content);

You need to escape the single quotes, or use double quotes like this:

$content = str_replace("<div id='demo'><a href='https://www.example.com' target='_blank'><img alt='Demo' src='//example.com/image.png' /></a></div>", '', $content)

You must escape all single quotes, like this:

    $content = str_replace(
        '<div id=\'demo\'><a href=\'https://www.example.com\' target=\'_blank\'><img alt=\'Demo\' src=\'//example.com/image.png\' /></a></div>', '', $content
    );

First you should define the variable $content at your code

  $content = str_replace('<div id='demo'><a href='https://www.example.com' target='_blank'><img alt='Demo' src='//example.com/image.png' /></a></div>', '', $content);

$content will refer to what?

I will give you this suggestion :

 <?php

 $string='<div id="demo"><a href="https://www.example.com" target="_blank"><img alt="Demo" src="//example.com/image.png" /></a></div>something';
 $removed='<div id="demo"><a href="https://www.example.com" target="_blank"><img alt="Demo" src="//example.com/image.png" /></a></div>';

 $content = str_replace($removed , '', $string);


 echo $content;// output something
 ?>