Reputation: 1827
I am trying to include a php function within a string but my syntax is wrong. Could anyone help please?
$string = "<div id=\"apostnav\"><span class=\"calcir b-" . $string=get_field('br_category');
$string=preg_replace("/[^a-zA-Z]/", "", $string);
echo strtolower($string) . "></span></div>";
Upvotes: 1
Views: 51
Reputation: 6712
Try this:
$string=get_field('br_category');
$string=preg_replace("/[^a-zA-Z]/", "", $string);
$string = "<div id=\"apostnav\"><span class=\"calcir b-" . strtolower($string) . "\"></span></div>";
I moved up two lines of code andn removed an echo
from the last one.
Here the code with few optimizations:
$string = get_field('br_category');
$string = preg_replace("/[^a-zA-Z]/", '', $string);
$stringLower = strtolower($string);
$string = "<div id='apostnav'><span class='calcir b-$stringLower'></span></div>";
Upvotes: 2