Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.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_Replace_Web Scraping - Fatal编程技术网

PHP替换括号和数字

PHP替换括号和数字,php,replace,web-scraping,Php,Replace,Web Scraping,我已经创建了一个代码来删除网站上的一些数据,现在我只需要不带括号和数字的数据 这是我的代码,但它只能替换整数,不能替换括号 foreach ($nodes as $node) { $span = $node->childNodes; $categories = preg_replace("/[0-9]/", '', $span->item(0)->nodeValue); echo '<br>' . '<font color="green">' . $ca

我已经创建了一个代码来删除网站上的一些数据,现在我只需要不带括号和数字的数据

这是我的代码,但它只能替换整数,不能替换括号

foreach ($nodes as $node) {
$span = $node->childNodes;
$categories = preg_replace("/[0-9]/", '', $span->item(0)->nodeValue);
echo '<br>' . '<font color="green">' . $categories . ' : ' . '</font>' ;
foreach($nodes作为$node){
$span=$node->childNodes;
$categories=preg_replace(“/[0-9]/”,“$span->item(0)->nodeValue);
回显“
”。$categories.:”;

如何替换括号呢?Tq

您可以将括号添加到preg\u replace模式中

$categories = preg_replace("/[0-9()]/", '', $span->item(0)->nodeValue);
或者,使用str_replace而不是preg_replace来实现更快、更高效的代码

$search = array(0,1,2,3,4,5,6,7,8,9,'(',')');
$categories = str_replace($search, '', $span->item(0)->nodeValue);