0

How I replace my eregi_replace with preg_replace expression?
eregi_replace($word, '<font style="background:' . $color . '";>\0</font>', $text);

and I how do I check preg_replace function is executed or not?

Edited by abhi10kumar

2
Contributors
1
Reply
15
Views
1 Year
Discussion Span
Last Post by cereal
1

Hi,

just add delimiters to the pattern variable, in your case it's $word, for example:

<?php

    $color = 'red';
    $text  = 'This is an example text sentence.';

    $eregPattern = 'example';
    $pregPattern = '/example/';

    $replacement = '<font style="background:' . $color . ';">\0</font>';

    echo eregi_replace($eregPattern, $replacement, $text);
    print PHP_EOL;

    echo preg_replace($pregPattern, $replacement, $text);
    print PHP_EOL;

I how do I check preg_replace function is executed or not?

From the documentation:

preg_replace() returns an array if the subject parameter is an array, or a string otherwise.

If matches are found, the new subject will be returned, otherwise subject will be returned unchanged or NULL if an error occurred.

Edited by cereal

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.