开发者

PHP/PEAR SearchReplace - String is "varyingText" - How to replace "varyingText" with "newVaryingText"?

开发者 https://www.devze.com 2023-04-08 17:03 出处:网络
I have a simple application based on the 开发者_如何学Cphp pear class SearchReplace: // Define result of Activate click

I have a simple application based on the 开发者_如何学Cphp pear class SearchReplace:

// Define result of Activate click
    if (isset($_POST['action']) and $_POST['action'] == 'Activate')
{   
    include "$docRoot/includes/pear/SearchReplace.php" ;
    $files = array( "$docRoot/promotions/index.php" ) ;
    $snr = new File_SearchReplace( '$promoChange = "";', '$promoChange = "'.$currentYear.'/'.$currentPromotion.'";', $files) ;
    $snr -> doSearch() ;
}

Notice the string that it is configured to search for:

$promoChange = "";

What I need to do, is replace this string, when there is a varying value assigned to the variable $promoChange So basically, what I am trying to replace would look something like this:

$promoChange = "2011/sep-oct";

I would need something along the lines of:

$promoChange = "%";

What would be the correct way of doing this?

If anyone has any input in this matter, it would be appreciated greatly,

Thank You!


You could open the file and replace using regex manually. The regex you need probably looks something like:

$text = preg_replace(
    '/\$promoChange = "[^"]*";/',
    '$promoChange = "' . $currentYear . '/' . $currentPromotion . '"',
    $text
);

I would caution against using something like this for anything more complicated.

0

精彩评论

暂无评论...
验证码 换一张
取 消