Reputation: 807
This is my html code:
<div style="box-sizing: border-box;
color: rgb(37, 37, 37);
font-family: Axiforma-Regular;
font-size: 16px;">
</div>
I want to replace these inline css double quote with single quote.
I tried this:
$display_box_content = '<div style="box-sizing: border-box;
color: rgb(37, 37, 37);
font-family: Axiforma-Regular;
font-size: 16px;">
</div>'
$display_box_content = str_replace('"', "'", $display_box_content);
but these does not work.
Please help!
Upvotes: 1
Views: 8648
Reputation: 87
$display_box_content = str_replace('\'', "\"", $display_box_content);
Upvotes: 0
Reputation: 807
i was using htmlentites function like this:
$display_box_content = htmlentities($display_box_content);
$display_box_content = str_replace('"', "'", $display_box_content);
so i just swapped those lines to this:
$display_box_content = str_replace('"', "'", $display_box_content);
$display_box_content = htmlentities($display_box_content);
and it worked. Thanks everybody for your help!
Upvotes: 2
Reputation: 993
You can do like following if you want to replace single quote with double quote in a php string.
$replacedString = str_replace(chr(39), chr(34),$display_box_content);
//chr(39) implies single quote
//chr(34) implies double quote
You can read about chr() function in php from this link
Upvotes: 0
Reputation: 157
You just have to use single-qoutes instead?
$display_box_content = "<div style='box-sizing: border-box; color: rgb(37, 37, 37); font-family: Axiforma-Regular; font-size: 16px;'></div>"
Upvotes: -1
Reputation: 1716
You're missing a ;
on line 1.
$display_box_content = '<div style="box-sizing: border-box; color: rgb(37, 37, 37); font-family: Axiforma-Regular; font-size: 16px;"></div>'; //added a ; here
$display_box_content = str_replace('"', "'", $display_box_content);
This code actually works; Please see 3v4l
Upvotes: 3