2

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
    }

5 Answers5

2

Use this:

$strua='1 325';
$strua = str_replace(' ', '', $strua);

Also read more about str_replace.

Code Lღver
  • 15,573
  • 16
  • 56
  • 75
0

to remove spaces:

$str = str_replace(" ","",$str);
steven
  • 4,868
  • 2
  • 28
  • 58
0

Use str_replace() with trim():

$string = '1 325';
$string = str_replace(' ', '', trim($str));

Documentation: str_replace(), trim()

0

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
Sunil Kumar
  • 1,389
  • 2
  • 15
  • 32
0

Here what solved the problem.

$strua='грн';
    if(strpos($variant['price'],$strua) !== false){

  $variant_price = str_replace(' ', '', $variant['price']);
  $variant['price']=$variant_price;
        }
Termininja
  • 6,620
  • 12
  • 48
  • 49