0

I have having a hard time with this problem and anything that I try seems not to work. This is the code that I am working with

if (strpos($content,'{blog:blogtitle}') !== false) {
   echo 'true';
}
echo $blogname;
if($blogname != ""){
   $replaced_content = str_replace('{blog:blogtitle}', $blogname, $content);
}else{
   $replaced_content = str_replace("{blog:blogtitle}", '', $content);
}

I get the true and the $blogname to echo, but for the life of me it will not replace. not even preg_replace works.

4
Contributors
7
Replies
41
Views
3 Years
Discussion Span
Last Post by itisnot_me
0

Any one know why it would not be working. I do this in other classes just fine. I even copied str_replace functions from working ones and still no luck.

0

what are the errors you get
Kindly check error log for the same.

Edited by code_rum

0

Thats the best part. Not one error printed or in a log about this. I have triple checked to make sure my code is not skipping something and its not.

0

It seems you want to search and replace a string in a json encoded array, correct? If yes, then each element is probably surrounded by quotes, example:

$a['blog'] = 'blogtitle';
echo json_encode($a);

// outputs {"blog":"blogtitle"}

Which is different from {blog:blogtitle}, the correct code should be:

if($blogname != "")
{
    $r = str_replace('{"blog":"blogtitle"}', '', $content);
}
else
{
    $r = str_replace('{"blog":"blogtitle"}', $blogname, $content);
}

echo $r;
0

I still couldnt figure out what it was. maybe i didnt send through the $replaced_content somewhere. So i just re wrote the code. Thanks anyways.

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.