Home >Backend Development >PHP Tutorial >javascript - php 如何才能转义html?

javascript - php 如何才能转义html?

WBOY
WBOYOriginal
2016-06-06 20:18:331168browse

我有一段html代码

<code><p><img src="%5C%5C%5C%22http:%5C/%5C/localhost%5C/wp-content%5C/uploads%5C/2016%5C/02%5C/20160212050255_865.png%5C%5C%5C%22" alt='\\\"\\\"'>\n</p>
<p><img src="%5C%5C%5C%22http:%5C/%5C/localhost%5C/wp-content%5C/uploads%5C/2016%5C/02%5C/20160212050312_659.png%5C%5C%5C%22" alt='\\\"\\\"'>\n"</p></code>

我需要获取到src里面的图片地址,而且不是什么\/\/这样的东西的...

我使用了正则表达式后

<code>$preg = '/<img . alt="javascript - php 如何才能转义html?" >/i';</img.></code>

返回的内容是

<code>"\\\"http:\/\/localhost\/wp-content\/uploads\/2016\/02\/20160212050312_659.png"</code>

而我需要的是干净的图片地址...http://localhost/wp-content/uploads/2016/02/20160212050312_659.png

我该怎么办。

回复内容:

我有一段html代码

<code><p><img src="%5C%5C%5C%22http:%5C/%5C/localhost%5C/wp-content%5C/uploads%5C/2016%5C/02%5C/20160212050255_865.png%5C%5C%5C%22" alt='\\\"\\\"'>\n</p>
<p><img src="%5C%5C%5C%22http:%5C/%5C/localhost%5C/wp-content%5C/uploads%5C/2016%5C/02%5C/20160212050312_659.png%5C%5C%5C%22" alt='\\\"\\\"'>\n"</p></code>

我需要获取到src里面的图片地址,而且不是什么\/\/这样的东西的...

我使用了正则表达式后

<code>$preg = '/<img . alt="javascript - php 如何才能转义html?" >/i';</img.></code>

返回的内容是

<code>"\\\"http:\/\/localhost\/wp-content\/uploads\/2016\/02\/20160212050312_659.png"</code>

而我需要的是干净的图片地址...http://localhost/wp-content/uploads/2016/02/20160212050312_659.png

我该怎么办。

http://php.net/manual/en/function.stripcslashes.php

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn