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.

$replaced_content

$content just has the original sting of html.

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.

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

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.

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;

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.

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.