This question already has an answer here:
Please help! I have the pricelist in CSV format. Prices are shown like 1 space 325. Instead of 1325. So the script takes only first argument of that price. How can I pass whole price. Here is what I am intending to use:
$strua='UAH';
if(strpos($variant['price'],$str) !== false){
//removing space sign
}
</div>
to remove spaces:
$str = str_replace(" ","",$str);
Use str_replace()
with trim()
:
$string = '1 325';
$string = str_replace(' ', '', trim($str));
Documentation: str_replace()
, trim()
Remove Whitespace:
$ro = preg_replace('/\s/', '',$str]);
Example:
<?php
$str ="1 325";
$ro = preg_replace('/\s/', '',$str);
echo $ro;
?>
Output:
1325
Note:
\s => Single Whitespace
\s+ => Excess whitespace
Here what solved the problem.
$strua='грн';
if(strpos($variant['price'],$strua) !== false){
$variant_price = str_replace(' ', '', $variant['price']);
$variant['price']=$variant_price;
}