2013-08-09 5 views
2

도와주세요! CSV 형식의 pricelist가 있습니다. 가격은 1 스페이스 325와 같이 표시됩니다. 1325 대신.이 스크립트는 해당 가격의 첫 번째 인수 만 취합니다. 어떻게하면 전체 가격을 전달할 수 있습니다. 여기에 사용하고자하고 무엇 :PHP를 사용하여 공간을 제거하십시오

$strua='UAH'; 
    if(strpos($variant['price'],$str) !== false){ 
    //removing space sign 
    } 
+0

더 큰 코드 예를 게시하면 도움이 될 것입니다. – GreenRover

+0

['str_replace'] (http://php.net/manual/en/function.str-replace.php) – naththedeveloper

+0

을보십시오.이 $ string = preg_replace ('/ \ s /', '', $ original_string); –

답변

2

사용이 :

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

은 또한 str_replace에 대해 더 읽어 보시기 바랍니다.

0

공백을 제거 :

$str = str_replace(" ","",$str); 
0

사용 str_replace()trim()로 :

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

문서 : str_replace(), trim()

+0

과 일치 할 수 있습니다. 왜 그가 트림을 사용해야합니까? – Mike

0

은 공백을 제거

$ro = preg_replace('/\s/', '',$str]); 

예 :

<?php 
$str ="1 325"; 
$ro = preg_replace('/\s/', '',$str); 
echo $ro; 
?> 

출력 :

1325 

참고 : 문제를 해결 여기에서

\s => Single Whitespace 
\s+ => Excess whitespace 
0

.

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

    $variant_price = str_replace(' ', '', $variant['price']); 
    $variant['price']=$variant_price; 
     } 
관련 문제