0

I need to replace \" from image src.

I have one form and i use the FCK editor for Details and when i upload image and submit a form then after i get below value in post

<img scr="\"http://test.in/public/admin/uploadfiles/Lighthouse(2).jpg\"">

So i need to remove \" from starting and \" from end so its display properly to me. I also try ltrim() and strreplace() but when i put some other things then it replace each place so i need to replace it only in img scr must start and end \" only

Any why to do this. I think this is possible using Regular expression but i have not enough knowledge for it.

Please suggest me any idea.

4

4 回答 4

3

在您的 php 配置中禁用 magic_quotes,然后编辑所有出现此错误的文本以进行更正。

于 2013-09-04T18:10:31.327 回答
1

更改 php.ini 设置magic_quotes_gpc = Off。如果您不能这样做,请ini_set在 php 代码本身中使用。如果您不能这样做请使用您获得stripslashes的价值。$_POST

于 2013-09-04T18:12:09.603 回答
1

我同意@Lee 的说法,但是如果你需要通过正则表达式来做到这一点。这应该这样做。

<?php
    $pattern = '/\\\"/';
    $replacement =  '';
    $subject = '<img scr="\"http://test.in/public/admin/uploadfiles/Lighthouse(2).jpg\"">';
    $result = preg_replace ($pattern, $replacement, $subject);
?> 
于 2013-09-04T19:07:23.950 回答
0

使用正则表达式,您可以执行以下操作:要删除第一个 \",请使用

preg_replace('/<img scr=\"\\\/', '<img scr=', $your_string); 

然后将第二部分替换为

preg_replace('/\\\\"\">/', '">', $your_string);
于 2013-09-04T18:42:32.240 回答