如何從下面$String
如何從PHP中的字符串中刪除'/ n'?
$String = "[email protected]:900/n";
我需要得到這樣的刪除/n
。
$new_string = "[email protected]:900";
如何從下面$String
如何從PHP中的字符串中刪除'/ n'?
$String = "[email protected]:900/n";
我需要得到這樣的刪除/n
。
$new_string = "[email protected]:900";
你可以試試這個。
<?php
$str = "[email protected]:900/n";
$str=str_replace("/n","",$str);
echo $str;
?>
$str = '[email protected]:900/n';
// Using regular expression
preg_replace('/\/n$/', '', $str);
// Straight up string replace
str_replace('/n', '', $str);
相反則表達式中使用PHP str_replace()
funtion的。
查找字符串'/n'
與''(empty)
在$String
可變
<?php
$String = "[email protected]:900/n";
echo $String;
echo '<br>';
$new_string = str_replace('/n', '', $String);
echo $new_string;
爲什麼一定替代是一個正則表達式?你寫什麼問題說,正則表達式? – deceze