如何更改从PHP简单HTML解析器解析的文本? [英] How to change the text parsed from PHP Simple HTML DOM Parser?

查看:134
本文介绍了如何更改从PHP简单HTML解析器解析的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法使用PHP Simple HTML DOM解析器解析来自另一个网站的文本。我设法解析的文本全部在HTML的< p> ...< / p> 中,类似于

I managed to parse text from another website using the PHP Simple HTML DOM Parser. The text I managed to parse is all in HTML's <p>...</p> which looks similar like this on the

源网站为:电话号码: 123456789

Source website as: Telephone Number: 123456789

但在我的网站上看到的是:电话号码:123456789。

but is looking on my website as: Telephone Number: 123456789.

我想电话号码和类似字词为粗体(如在源网站中)或与CSS颜色不同的颜色的网站。可以这样做吗?

I would like the words 'Telephone Number' and similar words to be bold (like in the source website) or in a different color than the CSS colour of my website. Can this be done?

我需要这个来复制我国教会在我国教会网站的各种HTML页面上的细节。我已经获得使用信息的权限。

I need this to copy the details off various HTML pages of my Church's website of my country's parishes in my country. I already obtained permission to use the information.

我尝试google,但没有找到任何解决方案。

I tried to google it but didn't find any solutions.

推荐答案

如果知道要替换的确切字符串,可以使用str_replace

if you know the exact string you want to replace you can use str_replace

$string = '<p>This is my super dupa text and it has my phone number: 083 23212212 32</p>';
$string = str_replace("phone number:", "<b>phone number:</b>", $string);

字符串现在具有粗体字'phone number:'。如果你有一些东西要替换你可以使用str_replace数组。请查看php网站上的示例: http://php.net/manual /en/function.str-replace.php

String now has 'phone number:' in bold. If you have a number of things to replace you can use str_replace with arrays. look at the examples on the php website here: http://php.net/manual/en/function.str-replace.php

这篇关于如何更改从PHP简单HTML解析器解析的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆