Vaibhav Mav
Vaibhav Mav

Reputation: 5

Php replacing strings in html ouput

I am trying to replace the first string in the code

$confirmation_message = apply_filters("pmpro_confirmation_message",  $confirmation_message, false);
    $confirmation_message = preg_replace('mysite.com', 'mysite.com?true', $str, 1);
    echo $confirmation_message;

But it is giving me a weird error

   Delimiter must not be alphanumeric or backslash line

Here's the original output of $confirmation_message

   <p><font><font class="">Visit your new site here: </font></font><a href="mysite.com/"><font><font class="">mysite.com</font></font></a></p>

  <p><font><font class="">Manage your new site here: </font></font><a href="mysite.com/wp-admin/"><font><font class="">mysite.com/admin</font></font></a></p>

Upvotes: 0

Views: 58

Answers (1)

Viktor
Viktor

Reputation: 3536

As @Piotr Olaszewski commented, you need to add the delimiters to the pattern.

$confirmation_message = preg_replace('/mysite\.com/', 'mysite.com?true', $confirmation_message, 1);

Note the escaped dot in the pattern as well.

Had you wanted to replace all occurrences of mysite.com, you could have used str_replace for better performance:

$confirmation_message = str_replace('mysite.com', 'mysite.com?true', $confirmation_message);

Upvotes: 1

Related Questions