Reputation: 33
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.
Upvotes: 1
Views: 332
Reputation: 281
Try the Heredoc Syntax
$replacement = <<<LINK
<a href="mailto:[email protected]">Contact Us</a>
LINK;
Upvotes: 0
Reputation:
Your code seems to be a complex way of doing this
function availability_filter_func($availability) {
$default = "Out of Stock";
$string = "<a href='mailto:[email protected]'>Contact Us</a>";
if($availablity !== "") {
$return = $availability;
} else {
$return = $default;
}
return "$return - $string";
}
Upvotes: 2