preg_match_all not returning expected values

倖福魔咒の 提交于 2019-12-12 19:05:55

问题


The code below uses a Wikipedia API to return data. I would like to output a string containing the Industry however cannot understand why the preg_match_all does not match and return the string related to industry - in this example of UBS, I would like to see "industry =[[Banking]], [[Financial services]]" returned. This string can be seen when using print_r to output data.
I'm sure I'm misunderstanding or missing something simple. Please assist.

<html>
<body>
<form method="post">
Search: <input type="text" name="q" value="UBS"/>
<input type="submit" value="Submit">
</form>

<?php
if (isset($_POST['q'])) {
$search = $_POST['q'];
$search = ucwords($search);
$search = str_replace(' ', '_', $search);
$url_2 = "http://en.wikipedia.org/w/api.php?
action=query&prop=revisions&rvprop=content&
format=json&titles=$search&rvsection=0&continue=";
$res_2 = file_get_contents($url_2);
$data_2 = json_decode($res_2);

?>

<?php foreach ($data_2->query->pages as $r): 

?>

<?php foreach($r->revisions[0] as $a); 
print_r($a);
if (preg_match_all('/|industry += (.*)/i', $a, $result)) {

$industry = trim($result[0][0]);

echo $industry;
} 

?>

<?php endforeach;

?>

<?php 
}
?>

</body>
</html>

来源:https://stackoverflow.com/questions/32066282/preg-match-all-not-returning-expected-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!