创建多个字符串替换

时间:2016-04-10 04:39:02

标签: php xml plugins str-replace vbulletin

我试图更改模板中的多行。我使用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']);

我还需要添加另一个。

1 个答案:

答案 0 :(得分:1)

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