Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php从数据库中获取HTML文本_Php_Html_Regex - Fatal编程技术网

使用php从数据库中获取HTML文本

使用php从数据库中获取HTML文本,php,html,regex,Php,Html,Regex,我试图从存储为文本usnig php的数据库中获取一些数据。 文本可以是纯文本/或html文本 我想从数据库检索的文本中获取以下字段:城市、州、国家。 下面是文本可能的示例 country :- US state :- Washington city :- Bellingham 或 美国国家 华盛顿州 城市本根 或在div标签中相同 我已经为纯文本做过了。 我发现这很容易,因为我找到了换行符(行尾)并修剪了除所需内容之外的其余文本 但是在HTML的情况下,我面临的问题是,如何处理

我试图从存储为文本usnig php的数据库中获取一些数据。 文本可以是纯文本/或html文本

我想从数据库检索的文本中获取以下字段:城市、州、国家。 下面是文本可能的示例

country :- US
state   :- Washington
city    :- Bellingham


美国国家
华盛顿州
城市本根
或在div标签中相同

我已经为纯文本做过了。 我发现这很容易,因为我找到了换行符(行尾)并修剪了除所需内容之外的其余文本


但是在HTML的情况下,我面临的问题是,如何处理HTML文本。因为没有断线。不知道最好的方法是什么如果我使用strip_标签,它会返回同一行中的所有文本,即国家美国华盛顿州,你不能只做一些文本处理而不是HTML解析吗

$input = "<table><tr><td>country </td><td>US</td></tr><tr><td>state</td><td>Washington</td></tr><tr><td>city</td><td>Bingen</td></tr></table>";

$needle = array("<table>", "<tr><td>","</td<td>", "</td</tr>", "</table");
$replacements = array("","",":-","\n","");
$output = str_replace($needle, $replacements, $input);
$input=“国家/地区UsStateWashingOnCityBingen”;

$needle=array(“,”,“难道你不能做一些文本处理而不是HTML解析吗

$input = "<table><tr><td>country </td><td>US</td></tr><tr><td>state</td><td>Washington</td></tr><tr><td>city</td><td>Bingen</td></tr></table>";

$needle = array("<table>", "<tr><td>","</td<td>", "</td</tr>", "</table");
$replacements = array("","",":-","\n","");
$output = str_replace($needle, $replacements, $input);
$input=“国家/地区UsStateWashingOnCityBingen”;

$PINELE=array(“,”,“当您在数据库中存储html时,请使用html_entities()对它们进行编码,然后使用html_entity_decode()显示它们


在数据库中存储html时,请使用html_entities()对其进行编码,然后使用html_entity_decode()进行显示



我不太确定您想要的结果是什么。使用正则表达式,只需谷歌搜索即可。我不太确定您想要的结果是什么。使用正则表达式,只需谷歌搜索即可。感谢您的及时回复幸运的是,我用同样的方法做到了这一点:)但是谢谢你的确认你能帮我处理div结构吗?谢谢你的及时回复幸运的是我用同样的方法做到了:)但是谢谢你的确认你能帮我处理div结构吗?
<?php
$orig = "I'll \"walk\" the <b>dog</b> now";
$a = htmlentities($orig);
$b = html_entity_decode($a);
echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now
echo $b; // I'll "walk" the <b>dog</b> now
?>