如何 trim php 中特定字符后的字符串
How to trim a string after a specific character in php
我是 PHP 的新人,我在变量中保存了一些文本。我正在尝试检索第一个“/”字符后跟的文本。这是我尝试过的。
$var="xxxxx/ttt/tttt/tttt.txt";
echo $str . "<br />";
echo trim($str,"/");
输出必须是ttt/tttt/tttt.txt
。
如果我能得到一些帮助,我将不胜感激。谢谢。
你可以试试explode函数
$var="xxxxx/ttt/tttt/tttt.txt";
$split = explode('/', $var,2); // it will expload by first occurance of / (delimeter)
//$split[0] will contain "xxxxx"
echo $split[1]; // output = ttt/tttt/tttt.txt
根据重复,这是你的答案:
$data = "xxxxx/ttt/tttt/tttt.txt";
$whatIWant = substr($data, strpos($data, "/") + 1);
echo $whatIWant;
我是 PHP 的新人,我在变量中保存了一些文本。我正在尝试检索第一个“/”字符后跟的文本。这是我尝试过的。
$var="xxxxx/ttt/tttt/tttt.txt";
echo $str . "<br />";
echo trim($str,"/");
输出必须是ttt/tttt/tttt.txt
。
如果我能得到一些帮助,我将不胜感激。谢谢。
你可以试试explode函数
$var="xxxxx/ttt/tttt/tttt.txt";
$split = explode('/', $var,2); // it will expload by first occurance of / (delimeter)
//$split[0] will contain "xxxxx"
echo $split[1]; // output = ttt/tttt/tttt.txt
根据重复,这是你的答案:
$data = "xxxxx/ttt/tttt/tttt.txt";
$whatIWant = substr($data, strpos($data, "/") + 1);
echo $whatIWant;