如何替换space后剩下的所有内容?
How to replace everything is left after space?
我想替换 space 之后剩下的所有内容。
这是我的代码,结果将是“13215.00 13195.00”
<?php
function bacaHTML($url){
$data = curl_init();
curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($data, CURLOPT_URL, $url);
$hasil = curl_exec($data);
curl_close($data);
return $hasil;
}
$kodeHTML = bacaHTML('http://www.thislink.com');
$pecah = explode('<table width="139" border="0" cellspacing="0" cellpadding="0">', $kodeHTML);
$pecahLagi = explode('</table>', $pecah[2]); *// result will be "USD 13215.00 13195.00 SGD 9778.82 9758.82 EUR 14966.37 14866.37 AUD 10092.31 10012.31"*
$ngilang = substr($pecahLagi[0], 0, strpos($pecahLagi[0], 'SGD')); // result will be "USD 13215.00 13195.00"
$usdilang = strtr($ngilang, array('USD' => '<replacement>')); // result will be "13215.00 13195.00"
echo $usdilang;
?>
现在,该代码如何 运行 以便结果为“13195.00”
我试过了,但不行。
$pieces = explode(" ", $usdilang);
$secondPiece = $pieces[1];
echo $secondPiece;
谢谢。
您可以使用explode按空格分割字符串。
$myString = "13215.00 13195.00";
$pieces = explode(" ", $myString);
$firstPiece = $pieces[0];
$secondPiece = $pieces[1];
我想替换 space 之后剩下的所有内容。
这是我的代码,结果将是“13215.00 13195.00”
<?php
function bacaHTML($url){
$data = curl_init();
curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($data, CURLOPT_URL, $url);
$hasil = curl_exec($data);
curl_close($data);
return $hasil;
}
$kodeHTML = bacaHTML('http://www.thislink.com');
$pecah = explode('<table width="139" border="0" cellspacing="0" cellpadding="0">', $kodeHTML);
$pecahLagi = explode('</table>', $pecah[2]); *// result will be "USD 13215.00 13195.00 SGD 9778.82 9758.82 EUR 14966.37 14866.37 AUD 10092.31 10012.31"*
$ngilang = substr($pecahLagi[0], 0, strpos($pecahLagi[0], 'SGD')); // result will be "USD 13215.00 13195.00"
$usdilang = strtr($ngilang, array('USD' => '<replacement>')); // result will be "13215.00 13195.00"
echo $usdilang;
?>
现在,该代码如何 运行 以便结果为“13195.00”
我试过了,但不行。
$pieces = explode(" ", $usdilang);
$secondPiece = $pieces[1];
echo $secondPiece;
谢谢。
您可以使用explode按空格分割字符串。
$myString = "13215.00 13195.00";
$pieces = explode(" ", $myString);
$firstPiece = $pieces[0];
$secondPiece = $pieces[1];