我确实遇到了问题,在我的情况下,我选择了 将MYSQL数据库中的信息保存到$ data中。preg_replace用于替换变量的所有内容
和我有2个数组preg_replace。
这是一个例子:
$repl();
$repl[0] = '/bull/';
$repl[1] = '/found/';
$repl[2] = '/search/';
$replto();
$replto[0] = 'This is not a ballon';
$replto[1] = 'This has been found';
$replto[2] = 'Im looking for it';
$data = array();
$data[0] = '/mynickname/search';
$data[1] = '/somebulls/search';
$data[2] = '/mcdo/found';
$data[3] = '/bump/search';
$data[4] = '/blood/bull';
echo preg_replace($repl,$replto,$data);
好,但preg_replace函数的输出是这样的:
/mynickname/Im looking for it
/somebulls/Im looking for it
/mcdo/This has been found
/bump/Im looking for it
/blood/This is not a ballon
...但我想这样的输出:
Im looking for it
Im looking for it
This has been found
Im looking for it
This is not a ballon
我'新的PHP,我解决了很多问题,但这是一个问题,我还没有找到解决方案。
你能帮助我吗?
'strrpos'(http://php.net/strrpos)和'substr'(http://php.net/substr)的组合应该很容易做到。 –
那么,代码的工作原理与您的一样...我认为您的逻辑在这里不正确。如果将'search'替换为'Im正在寻找它',为什么你会认为'/ mynickname/search'会自动删除mynickname部分?它只是取代你告诉它的那部分。 – Charlie74
哇...很容易?...不适合我,我认为这只是addnal在“preg_replace”中的一个事情......就像在SQL中使用LIKE中的%一样。 – user3114471