0

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!

Saif Ahmad
  • 1,118
  • 1
  • 8
  • 24
Hetal Chauhan
  • 787
  • 10
  • 22
  • 2
    You forgot a semicolon at the end of your first line. Other than that, your code works just fine. http://sandbox.onlinephpfunctions.com/code/ef97b4719ff51e34ebeed0bf26daaa89971378d7 – HTMHell Nov 29 '17 at 09:58

5 Answers5

3

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

IsThisJavascript
  • 1,726
  • 2
  • 16
  • 25
1

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!

Hetal Chauhan
  • 787
  • 10
  • 22
0

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

nirazlatu
  • 983
  • 8
  • 18
-1
$display_box_content = str_replace('\'', "\"",, $display_box_content);
Erkin Pardayev
  • 77
  • 2
  • 10
  • thank you bro, i edited my answer, result is : http://sandbox.onlinephpfunctions.com/code/aa15d0c477b1582acfdcf338662fd033d24353cf – Erkin Pardayev Nov 29 '17 at 10:08
  • hey,i can see the code works in this: http://sandbox.onlinephpfunctions.com/code/aa15d0c477b1582acfdcf338662fd033d24353cf but if i copy paste this same code in to my local server and execute, then nothing is displayed, then this kind of some dummy string: ....string(115) " " string(115) " " ...is displayed – Hetal Chauhan Nov 29 '17 at 10:26
  • @user3856149 try setup xdebug or configure var_dump function in your php and configure. You can use this https://stackoverflow.com/questions/9998490/how-to-get-xdebug-var-dump-to-show-full-object-array – Erkin Pardayev Nov 29 '17 at 10:36
-1

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>"
Kalabalik
  • 99
  • 1
  • 10