Reputation: 5615
I need to output a string, which is basically a java code:
I have something like this:
$web = "...if (url.contains('.mp4'))..."
I need that the single quotation mark, will be a double one, and not in html code.
Is it possible to do it?
Upvotes: 8
Views: 32532
Reputation: 6403
You should use this
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?>
see http://docs.php.net/manual/en/function.htmlspecialchars.php
Upvotes: 0
Reputation: 145482
Short of doing a strtr()
replacement, just escape your double quotes:
$web = "...if (url.contains(\".mp4\"))..."
See http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double for the complete list of escaping rules.
Upvotes: 1
Reputation:
$new_str = str_replace('\'', '"', $web);
You could optional do it by modifying the actual string (note the use of \
to escape the quotation marks):
$web = "...if (url.contains(\".mp4\"))..."
Upvotes: 7