PHP-如何用另一个替换短语? [英] PHP - How to replace a phrase with another?
本文介绍了PHP-如何用另一个替换短语?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何用此<p class="headline"><span>
替换此<p><span class="headline">
使用PHP最简单.
How can i replace this <p><span class="headline">
with this <p class="headline"><span>
easiest with PHP.
$data = file_get_contents("http://www.ihr-apotheker.de/cs1.html");
$clean1 = strstr($data, '<p>');
$str = preg_replace('#(<a.*>).*?(</a>)#', '$1$2', $clean1);
$ausgabe = strip_tags($str, '<p>');
echo $ausgabe;
在更改网站的html之前,我要从跨度到<p>
标签获取类声明.
Before I alter the html from the site I want to get the class declaration from the span to the <p>
tag.
推荐答案
您是否尝试过使用 str_replace
?
Have you tried using str_replace
?
如果<p>
和<span>
标签的位置一致,则只需将其中一个替换为另一个
If the placement of the <p>
and <span>
tags are consistent, you can simply replace one for the other with
str_replace("replacement", "part to replace", $string);
这篇关于PHP-如何用另一个替换短语?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文