我想explode为所有人写一个字符串:
但这不起作用:
$keywords = explode("\n\t\r\a,-", "my string");
Run Code Online (Sandbox Code Playgroud)
怎么做?
我可不可以做:
explode("\n", $_POST['thetextarea']);
Run Code Online (Sandbox Code Playgroud)
并让它适用于所有平台?(我问的问题是它将永远是\ r \n而不只是\n")
编辑:
我忘了提到我将$ _POST ['thetextarea']保存到mysql数据库VARCHAR 255.似乎\ r \n转换为\n.
可能重复:
用于解除引用功能结果的PHP语法
我有一个字符串,看起来像1234#5678.现在我称之为:
$last = explode("#", "1234#5678")[1]
Run Code Online (Sandbox Code Playgroud)
它不起作用,有一些语法错误......但在哪里?我期待的是5678 in $last.这不适用于PHP吗?
有没有办法使用分隔符数组来爆炸()?
PHP手册:
array explode(string $ delimiter,string $ string [,int $ limit])
而不是使用string $delimiter是否有任何方式使用array $delimiter而不会影响性能太多?
我需要在逗号中将我的字符串输入分解为数组.但是该字符串在引号内包含逗号.
输入:
$line = 'TRUE','59','A large number is 10,000';
$linearray = explode(",",$line);
$linemysql = implode("','",$linearray);
Run Code Online (Sandbox Code Playgroud)
返回$ linemysql为:
'TRUE','59','A large number is 10','000'
Run Code Online (Sandbox Code Playgroud)
我怎样才能完成这个,爆炸忽略引号内的逗号?
这可能听起来像一个愚蠢的问题,但是:当使用它来提取php中的搜索查询中的关键字时,这会更快:
$keyword = preg_split('/[\s]+/', $_GET['search']);
Run Code Online (Sandbox Code Playgroud)
要么
$keyword = explode(' ', $_GET['search']);
Run Code Online (Sandbox Code Playgroud) 你能在一行代码中写下以下内容吗?
$foo = explode(":", $foo);
$foo = $foo[0];
Run Code Online (Sandbox Code Playgroud) $str = "This is a string";
$words = explode(" ", $str);
Run Code Online (Sandbox Code Playgroud)
工作正常,但空间仍然进入数组:
$words === array ('This', 'is', 'a', '', '', '', 'string');//true
Run Code Online (Sandbox Code Playgroud)
我更喜欢只有没有空格的单词,并保留有关空格数量的信息.
$words === array ('This', 'is', 'a', 'string');//true
$spaces === array(1,1,4);//true
Run Code Online (Sandbox Code Playgroud)
刚添加:(1, 1, 4)表示第一个单词后面的一个空格,第二个单词后面的一个空格和第三个单词后面的4个空格.
有什么方法可以快速完成吗?
谢谢.
我有一串id,如1,2,3,4,5,我希望能够列出mysql中包含该列表ID的所有行.
我假设最简单的方法是将字符串转换为数组然后匹配($ array)但它对我不起作用 - 没有错误等但它不返回任何行:
$string="1,2,3,4,5";
$array=array_map('intval', explode(',', $string));
$query=mysqli_query($conn, "SELECT name FROM users WHERE id IN ('".$array."')");
Run Code Online (Sandbox Code Playgroud)
如果我执行$ array的var_dump,我得到:
array(5) {
[0]=> int(1)
[1]=> int(2)
[2]=> int(3)
[3]=> int(4)
[4]=> int(5)
}
Run Code Online (Sandbox Code Playgroud)
知道我搞砸了吗?
explode ×10
php ×10
arrays ×4
string ×3
c++ ×1
equivalent ×1
mysql ×1
preg-match ×1
preg-split ×1
regex ×1
split ×1