创建多个字符串替换

creating more than one string replace

我正在尝试更改模板中的多行。我用的是vBulletin软件

这是我的:

$drcidl_inc = '<!-- / CSS Stylesheet -->';
$drcidl_cr = '$vbphrase[powered_by_vbulletin]';
$drcrb_hd = '<textarea name=\"message\" id=\"{$editorid}_textarea\" rows=\"10\" cols=\"60\" style=\"width:100%; height:{$editor_height}px\" tabindex=\"1\" dir=\"$stylevar[textdirection]\"></textarea>';
$find = '<textarea name=\"message\" id=\"{$editorid}_textarea\"';
$replace = '<textarea class=\"form-control comment-form-textarea\" name=\"message\" id=\"{$editorid}_textarea\"';
if(strpos($vbulletin->templatecache['headinclude'],$drcidl_inc) !==false)$vbulletin->templatecache['headinclude'] = str_replace($drcidl_inc,fetch_template('drc_iiu_css').$drcidl_inc,$vbulletin->templatecache['headinclude']);
else $vbulletin->templatecache['headinclude'] .= fetch_template('drc_iiu_css');
$vbulletin->templatecache['showthread_quickreply'] = str_replace($find,$replace,$vbulletin->templatecache['showthread_quickreply']);
$vbulletin->templatecache['showthread_quickreply'] = str_replace($drcrb_hd,$drcrb_hd.fetch_template('drc_iiu_below_txtarea'),$vbulletin->templatecache['showthread_quickreply']);
$vbulletin->templatecache['footer'] = str_replace($drcidl_cr,$drcidl_cr.fetch_template('drc_iiu_js'),$vbulletin->templatecache['footer']);

这有效,但只有第一个 showthread_quickreply str_replace 有效。 我不确定如何准确表达这个问题,但我如何在一个...变量上使用多个 str_replace?

这是我要合并的那个:

$vbulletin->templatecache['showthread_quickreply'] = str_replace($find,$replace,$vbulletin->templatecache['showthread_quickreply']);
$vbulletin->templatecache['showthread_quickreply'] = str_replace($drcrb_hd,$drcrb_hd.fetch_template('drc_iiu_below_txtarea'),$vbulletin->templatecache['showthread_quickreply']);

而且我还需要再添加一个。

str_replace是一个正规的php函数,答案是肯定的。您可以使用数组来做到这一点。

但是,您确实需要确保数组具有相同的索引。

$phrase  = "You should eat fruits, vegetables, and fiber every day."; //in your case the vBulletin data
$healthy = array("fruits", "vegetables", "fiber"); //What you want to find
$yummy   = array("pizza", "beer", "ice cream"); //What you want to replace

$newphrase = str_replace($healthy, $yummy, $phrase);

结果:

You should eat your pizza, beer, and ice cream every day.

取自:http://php.net/manual/en/function.str-replace.php