Block of text with two types of quotes as a string

I work with a website based on some user-defined template system. Let's say that in the template I can use the [custom_text] tag , which will display the entire html block, like this, defined in the CMS text editor:

<b>Lorem ipsum dolor</b> sit amet, "consectetur adipisicing elit"<br /><br />
<b>sed doeiusmod</b> tempor incididunt ut labore et dolore magna aliqua.

Please note that it contains both types of quotes. I cannot preprogram everything that comes out of the template system, except to actually output it to the page, since the CMS system with the template system is encoded.

Now I really need to manipulate this block, for example, to remove all line breaks from the code. I can use php on the page, but I can not determine the line that will contain this block of code. If I do this anyway:

$string = "[custom_text]";
$string = '[custom_text]';

quotes in the block will appear on the path, ending the line prematurely. Is there an obvious way to deal with this problem?

+5
source share
2 answers

I don’t know why I didn’t think about it before, but I can just use the heredoc syntax.

$string = <<<EOT
[custom_text]
EOT;

will solve the case.

+3
source

Try this one

<?php
$string = "This string has 'single quotes'";
echo addcslashes($string, '"\\');
?>

Result will be lower

This string has 'single quotes'

This answer is from this link.

Press here

0
source

All Articles