I am trying to replace a certain string with some PHP code using the str_replace function. I want to replace "[GOOGLE]" with <?php echo "hello"; ?>
Here's what I have so far:
$text = str_replace("[GOOGLE]", "<?php echo 'hello'; ?>", $text);
When running this code, it does replace [GOOGLE], but the replacement is not shown in the browser. When I go to see the page's source code, the replacement is: <?php echo 'hello'; ?> you can see the PHP tag for some reason. However, nothing is displayed on the page. How do I correct this problem so that [GOOGLE] is replaced with hello? Note: I do not want to replace my PHP code in the str_replace function with the actual "hello" string, I want to do this with PHP code. For now, I am trying to go with something simple. My goal is to replace [GOOGLE] with an if/else statement and Ad code for my CMS.
hellostr_replaceand replace with PHP code inside PHP tags, that PHP code does not get evaluated. You would have to use something like eval (Don't use eval). So instead you get a literal<?php ... ?>which your browser just thinks is a long HTML element because it is within angle brackets. Therefore it doesn't even show that output in your browser (unless you view source). Bottom line, just usehelloas Ghost said.