[英]remove quotes inside quotes regex php
My String goes like this: 我的弦是这样的:
[...]
if(round($pdf->GetY() >= 140)) {
$pdf->AddPage();
}
$pdf->Write(6,'Dutzler, Herbert - Letzter' Saibling');
$pdf->Ln(7);
$pdf->SetFont('Helvetica','B',9);
$pdf->SetTextColor(3 [...]
As you can see, FPDF cannot execute this command: 如您所见,FPDF无法执行以下命令:
$pdf->Write(6,'Dutzler, Herbert - Letzter' Saibling');
because there is a quote inside quotes and it crashes. 因为引号内有一个引号,它会崩溃。
Do you have any idea how I can remove or replace those inner quotes using regex? 您是否知道如何使用正则表达式删除或替换这些内引号? I have tried many different things, seems not to work properly :(
我尝试了许多不同的方法,似乎无法正常工作:(
the code is coming from a huge database, here's a peek at the input code: 该代码来自一个巨大的数据库,下面是输入代码的一览表:
[LOOP] $pdf->Write(6,'[title]');
[LOOP] $ pdf-> Write(6,'[title]'); $pdf->Ln(7);
$ pdf-> Ln(7); $pdf->SetFont('Helvetica','B',9);
$ pdf-> SetFont('Helvetica','B',9); [LOOP]
[环]
str_replace doesn't work properly if there are quotes inside [title] so it already fails at $str='[title]'. 如果[title]中有引号,则str_replace无法正常工作,因此它在$ str ='[title]'处已经失败。 It's weird, I know.
我知道这很奇怪。
Either escape the inside quote: 要么转义内部引号:
$pdf->Write(6,'Dutzler, Herbert - Letzter\' Saibling');
or use double quotes around the string instead of single quotes: 或在字符串周围使用双引号而不是单引号:
$pdf->Write(6,"Dutzler, Herbert - Letzter' Saibling");
No need for regexp, just write the code correctly in the first place. 无需regexp,只需首先正确编写代码即可。
Have you tried addslashes()? 您是否尝试过addlashes()? It should add slashes before quotes.
它应该在引号之前添加斜杠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.