php的str_replace函数怎么把<p><br/></p>替换掉呢?

php的str_replace函数怎么把


替换掉呢?
最新回答
不要忘記

2020-11-17 14:46:41

  • php的str_replace函数怎么把<p><br/></p>替换掉方法如下

  $html="<p>fdasf</p>";

  echo $string = str_replace(array("<p>","","</p>"),"",$html);

  br<

http://bbs.houdunwang.com/>

  • 若是<p>     内容</p>替换成<p>内容</p>
    <p>                 content</p>替换成<p>contend</p>
    (空格是tab键和空格键  混合的  都有可能)方法如下

  $html=preg_replace('/[\n\r\t]/','',$html);//去空格

  • 若是<p>后面跟了若干个,再是内容 

  <p>     内容</p>

  替换成<p>内容</p>

  <p>   content</p>

  替换成<p>contend</p>

  <?php

  $html="<p>

  内容</p>替换成<p>内容</p>

  <p>content</p>替换成<p>contend</p>";方法如下

  $html=trim($html);

  $html=str_replace(PHP_EOL,"",$html);

  $html=str_replace(" ","",$html);

  $html=preg_replace('/\s+/','',$html);

  $html=preg_replace('/[\n\r\t]/','',$html);

  echo "{$html}";

  ?>

酒还酹江月

2024-01-26 15:13:27

可以使用 htmlentities()函数。
这个函数,可以将一些特殊字符替换掉,列如:<> 或替换成 > <等。
反函数:htmlspecialchars_decode()。

将特殊的 HTML 实体转换回普通字符。意思就是,将>; < 转换为 <>

如果需要往数据库添加,结合addslashes()函数。
这个函数,对引号进行转义,在添入数据时,不会因为引号问题而出错。
总结:addslashes(htmlentities($string))。
轻拥

2023-03-11 21:56:04

$html="<p><br/>fdasf</p>";
echo $string = str_replace(array("<p>","<br/>","</p>"),"",$html);
br被和谐了
差不多先森丶

2024-03-28 01:32:27

实例

把字符串 "Hello world!" 中的字符 "world" 替换为 "Shanghai":
<?php
echo str_replace("world","Shanghai","Hello world!");
?>
同理
等待亦是放下

2023-12-31 03:02:23

<?php
$vowels = array("<p>", "<br/>", "i", "</p>");
$onlyconsonants = str_replace($vowels, "", $str);
?>