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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.