I have a PHP function that is calling the following:
function availability_filter_func($availability) {
$replacement = 'Out of Stock - Contact Us';
if(is_single(array(3186,3518)))
$availability['availability'] = str_ireplace('Out of stock', $replacement, $availability['availability']);
}
As you can see I am replacing the text string with custom text, however
I need the "Contact Us" text to be <a href="mailto:[email protected]">Contact Us </a> - how would I go about doing this? Inputting raw html into the replacement string makes the html a part of the output.
Echo does not work and breaks the PHP function - same with trying to escape the PHP function, inserting html on on the entire string, and unescape the function.
Any advice would be appreciated, thank you.
htmlentities()orhtmlspecialchars()on the string, which encodes all the HTML markup. If you want to be able to put HTML into the string, you mustn't do that.str_ireplace("Out of stock", htmlentities("<p style="color:red">This text is red</p>")results in the PHP script breaking. I have also triedstr_ireplace("Out of stock", htmlentities('<p style="color:red">This text is red</p>')str_ireplacefunction, you're only close thehtmlentities. Also why are you running the htmlentitites, don't you want the HTML outputted?