在PHP字符串中搜索名称
我有一个php字符串,我正试图从中获取名称 字符串输出为“| name=thomas | country=usa”等 我希望能够将名称“thomas”输入到php变量中 注意:数据是动态的,所以我试图找到一种不用硬编码的搜索方法 这是我的密码:在PHP字符串中搜索名称,php,string,search,Php,String,Search,我有一个php字符串,我正试图从中获取名称 字符串输出为“| name=thomas | country=usa”等 我希望能够将名称“thomas”输入到php变量中 注意:数据是动态的,所以我试图找到一种不用硬编码的搜索方法 这是我的密码: $people= ($_GET['people']); preg_match_all('/name="([^"]+)"/mi', $people, $matches); var_dump ($matches[1]); 我在php中收到一个数
$people= ($_GET['people']);
preg_match_all('/name="([^"]+)"/mi', $people, $matches);
var_dump ($matches[1]);
我在php中收到一个数组到字符串的转换错误。使用此正则表达式
<?php
$str='| name=thomas | country=usa ';
preg_match_all('/=(.*?) /', $str, $matches);
print_r($matches[1][0]); //"prints" thomas
这是生成所讨论字符串的代码吗?在这种情况下,如何让$matches[1]
输出字符串?它应该输出一个数组,而不是为什么在模式中使用双引号?另外,请确切地告诉我们你的美元是什么样子的?总是这样吗<代码>“| name=thomas | country=usa”
谢谢,我认为这会搜索“=”及其后的任何内容,直到空格?:P
function yourSearch($haystack) {
$string= 'Enter value to search for';
return(strpos($mystack, $string)); // or stripos() if you want case-insensitive searching.
}
$matches = array_filter($your_array, 'yourSearch');