(PHP / Wordpress)当字符串输出短代码时,很容易删除字符,但不能删除'$'

NOTE: I've answered my own question below, but posting this anyway for someone else in my situation to learn...


This is driving me insane.

Here's the scenario. There are a million questions here about removing characters like '$' from simple strings (eg. $string = '$10.00') and I can do that just fine.

However... when the string originates from shortcode output (eg. $string = do_shortcode($mycode), I just can't do it. I can remove the 1's and 0's and .'s but the $ won't budge.

Note: The shortcode I'm using is 'Wordpress Currency Switcher' (wpcs_price). My newbie mind tells me that the problem is my string isn't a string at all, but live code or some weird type of array I don't understand.

Example.

function justwork() {
$rawprice = 10.00;
$rawpriceSC = '[wpcs_price value=\''.$rawprice.'\']'; 
$rawpriceOUT = do_shortcode($rawpriceSC); /* This will output $10.00 */
$finalprice = str_replace('$','',$rawpriceOUT);
echo $finalprice;
}

add_shortcode('justwork', 'justwork');

This will result in:

'$10.00' ($ not removed)

Using the same code on a different character (Eg. the '.') works just fine. Eg.

$finalprice = str_replace('.','',$rawpriceOUT);

And the output will be: '$1000'

The $ just won't budge. I've tried substr,trim,preg, lots of other stuff, and I soon realised all is not what it seems, it's carrying some baggage. So I tried capturing the output buffer, and still the resultant string behaved odd.

Any help... oh gosh please, going insane on this one.

ANSWER

While reviewing all the methods I'd looked at, one came up I hadn't.

echo htmlentities($finalprice);

And guess what this output?

<span class="wpcs_price" id="wpcs_58c296db36aa3" data-amount=10 ><span class="wpcs_price_symbol">&#36;</span>10.00</span>

OK. So either I need to use & # 3 6 ; instead of $, or I can operate on that whole mess to get my 10.00. Geeze.

Confirmed that simply replacing the '$' with '& # 3 6 ;' (remove spaces) works fine.

function justwork() {
$rawprice = 10.00;
$rawpriceSC = '[wpcs_price value=\''.$rawprice.'\']';
$rawpriceOUT = do_shortcode($rawpriceSC);

$price = str_replace('&#36;', '', $rawpriceOUT) ;

echo $price;

}   

add_shortcode('justwork', 'justwork');