Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.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 正在将字符串解析为数组并在页面上显示_Php_Parsing - Fatal编程技术网

Php 正在将字符串解析为数组并在页面上显示

Php 正在将字符串解析为数组并在页面上显示,php,parsing,Php,Parsing,我有一个字符串,用于简单的html解析器和类似的东西 <b>Atmosp'Hair, Caroline Michellod</b><i> in <a href="1" target="_top">Leytron</a></i>, Einzelunt., <a href="1" target="result">+++</a>, <a href="google.com" target="_blank

我有一个字符串,用于简单的html解析器和类似的东西

<b>Atmosp'Hair, Caroline Michellod</b><i> in <a href="1" target="_top">Leytron</a></i>, Einzelunt., <a href="1" target="result">+++</a>, <a href="google.com" target="_blank">CHE-137.645.261</a><a href="pdf" target="_blank">Download pdf</a>
<b>Bar La Gouttière, Y. Maret</b><i> in <a href="http://www.example.com">Dolor</a><a href="2" target="_top">Martigny</a></i>, Einzelunt., <a href="2" target="result">+++</a>, <a href="yahoo.com" target="_blank">CHE-112.712.556</a><a href="http:/wwww.coocc.com">Doloo</a>
<b>Catherine Michellod</b><i> in <a href="3" target="_top">Bagnes</a></i>, Einzelunt., <a href="3" target="result">+</a>, <a href="bing.com" target="_blank">CHE-111.755.770</a><a href="pdf" target="_blank">Download pdf</a>
<a href="google.com" target="_blank">CHE-137.645.261</a>
<a href="yahoo.com" target="_blank">CHE-112.712.556</a>
<a href="bing.com" target="_blank">CHE-111.755.770</a>
艾因策伦特的卡罗琳·米歇洛德的Atmosp'Hair。, 巴勒·拉古提埃,Y.马雷,埃因策伦特。, 凯瑟琳·米歇洛德,埃因策伦特。, 我需要的是从中获得新的数组,并在页面上显示如下

<b>Atmosp'Hair, Caroline Michellod</b><i> in <a href="1" target="_top">Leytron</a></i>, Einzelunt., <a href="1" target="result">+++</a>, <a href="google.com" target="_blank">CHE-137.645.261</a><a href="pdf" target="_blank">Download pdf</a>
<b>Bar La Gouttière, Y. Maret</b><i> in <a href="http://www.example.com">Dolor</a><a href="2" target="_top">Martigny</a></i>, Einzelunt., <a href="2" target="result">+++</a>, <a href="yahoo.com" target="_blank">CHE-112.712.556</a><a href="http:/wwww.coocc.com">Doloo</a>
<b>Catherine Michellod</b><i> in <a href="3" target="_top">Bagnes</a></i>, Einzelunt., <a href="3" target="result">+</a>, <a href="bing.com" target="_blank">CHE-111.755.770</a><a href="pdf" target="_blank">Download pdf</a>
<a href="google.com" target="_blank">CHE-137.645.261</a>
<a href="yahoo.com" target="_blank">CHE-112.712.556</a>
<a href="bing.com" target="_blank">CHE-111.755.770</a>

我曾尝试查找属性_blank,但有时会有另一个与该属性的链接,也曾尝试查找nt child,但有时会有另一个a标记。很多糟糕的HTML,唯一独特的是A href内部HTML以CHE

开头,仅用于获取所有匹配项,例如

<?php

    preg_match_all("/<[^>]*>CHE[^<]*<[^>]*>/", $str, $m);
    print_r($m[0]);

?>

输出:

Array
(
    [0] => <a href="google.com" target="_blank">CHE-137.645.261</a>
    [1] => <a href="yahoo.com" target="_blank">CHE-112.712.556</a>
    [2] => <a href="bing.com" target="_blank">CHE-111.755.770</a>
)
数组
(
[0] => 
[1] => 
[2] => 
)

找到所有链接并选择那些文本以CHE开头的链接是的,放入数组并像这样显示它你能帮我得到这样的数组$results=array=(数组([link]=>google.com[name]=>CHE-137.645.261)数组([link]=>yahoo.com[name]=>CHE-112.712.556)数组([link]=>bing.com[name]=>CHE-111.755.770))@MiomirDancevic只需将
[]
数组语法更改为
array()
就可以了,因为我尝试过仍然存在错误,你能写吗?