简体   繁体   English

用双引号php替换单引号

[英]Replace single quote with double quote php

This is my html code: 这是我的html代码:

 <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. 我想将这些内联CSS双引号替换为单引号。

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! 请帮忙!

You're missing a ; 你错过了; on line 1. 在第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 请参阅3v4l

Just do this 做这个

Interchange your quotes 交换报价

$display_box_content = "<div style='box-sizing: border-box; color: rgb(37, 37, 37); font-family: Axiforma-Regular; font-size: 16px;'></div>";

Done 完成

$display_box_content = str_replace('\'', "\"",, $display_box_content);

您只需要使用单行?

$display_box_content = "<div style='box-sizing: border-box; color: rgb(37, 37, 37); font-family: Axiforma-Regular; font-size: 16px;'></div>"

You can do like following if you want to replace single quote with double quote in a php string. 如果要将php字符串中的双引号替换为单引号,可以执行以下操作。

  $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 您可以从此链接中了解有关php中的chr()函数的信息

i was using htmlentites function like this: 我正在使用这样的htmlentites函数:

$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! 谢谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM