Search code examples
phpxmlpluginsstr-replacevbulletin

creating more than one string replace


I'm trying to change multiple lines in a template. I use vBulletin software.

This is what I have:

$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']);

This works but only the first showthread_quickreply str_replace is functioning. I'm not sure exactly how to phrase this question, but how can I use multiple str_replace's on one ...variable?

This is the one I'm trying to merge:

$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']);

and I will need to add another one to it still too.


Solution

  • str_replace is a regular php function, and the answer is yes. You can use arrays to do so.

    You do, however, need to make sure that the arrays have equal indexes.

    $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);
    

    result:

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

    taken from: http://php.net/manual/en/function.str-replace.php