许多人建议我将名字和姓氏分开而不是"full_name"中的所有内容,如何将它们分隔到每个变量中,所以如果为你的例子输入字段:"Dude Jackson"然后"Dude"获得$ firstname和杰克逊在$姓.
在PHP中,我正在搜索特定文本中的语音.我explode()用来分隔不同部分的文本,使用我正在搜索的城市的区号作为分隔符.问题是包含与区号相同数字的phonenumbers 不能很好地返回.
例如:
"foofoo 010-1234567 barbar"分裂成"foofoo "和"-1234567 barbar"
但
"foofoo 010-1230107 barbar"分裂成"foofoo ","-123"和"7 barbar"!
我可以使用第一个用areacode重建phonenummer,但第二个当然错了...
我想我需要一个正则表达式来分割文本,使用某种机制不分裂在短字符串上,而不是explode(),但我不知道该怎么做.
在文本中搜索phonenumbers的任何想法或更好的方法?
更新: 格式不一致,因此寻找连字符是没有解决方案的.有些电话号码在区号和号码之间有空格,有些有挂钩,有些没有,等等.荷兰语的电话号码有2,3或4个号码,通常总共10个号码.
我遇到以下内容将字符串拆分为"令牌":
$tokens = preg_split("/[^\-_A-Za-z0-9]+/", $string);
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释这与此有何不同:
$tokens = explode(' ', $string);
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激 :-)
我有以下字符串的数组.首先我使用爆炸"\n"和输出如下.
[1]=> string(121) "/Microsoft/Windows/Ravemp2300Handler/DeviceArrival/a.exe"
[2]=> string(139) "/Microsoft/Windows/EventHandlers/Ravemp2300Arrival/b.exe"
[3]=> string(89) "/Microsoft/Windows/DeviceHandlers/Rio600Handler/c.exe"
[4]=> string(103) "/Microsoft/Windows/Rio600Handler/EventHandlers/d.exe"
Run Code Online (Sandbox Code Playgroud)
以下数组将提取a.exe,b.exe等,如下所示.
[1]=> string(121) "a.exe"
[2]=> string(139) "b.exe"
[3]=> string(89) "c.exe"
[4]=> string(103) "d.exe"
Run Code Online (Sandbox Code Playgroud)
谁有想法如何解决问题?对此,我真的非常感激.先感谢您.
我得到了解决方案,感谢Leven和EmilVikström的替代解决方案.
$array2 = array_map('basename', $array1);
Run Code Online (Sandbox Code Playgroud) 我正在构建一个类,它返回一个字符串,该字符串将自动包含文件夹中的文件,有点像HTML文件的加载器.
这是将被调用的方法:
function build_external_file_include($_dir){
$_files = scandir($_dir);
$_stack_of_file_includes = "";//will store the includes for the specified file.
foreach ($_files as $ext){
//split the file name into two;
$fileName = explode('.',$ext, 1);//this is where the issue is.
switch ($fileName[1]){
case "js":
//if file is javascript
$_stack_of_file_includes = $_stack_of_file_includes."<script type='text/javascript' src='".$dir.'/'. $ext ."'></script>";
break;
case "css";//if file is css
$_stack_of_file_includes = $_stack_of_file_includes."<link rel=\"stylesheet\" type=\"text/css\" href=\"".$dir.'/'. $ext."\" />";
break;
default://if file type is unkown
$_stack_of_file_includes = $_stack_of_file_includes."<!-- File: ". $ext." was not included-->"; …Run Code Online (Sandbox Code Playgroud) 我对DB的一个csv导入有一个字段值,看起来像'24h 30m'
我如何将这个分开两组数字?这是我到目前为止所拥有的
$tasktime = "24h 30m";
$pieces = explode("h ", $tasktime);
echo $pieces[0]; // want this to echo 24
echo $pieces[1]; // want this to echo 30
Run Code Online (Sandbox Code Playgroud) 我有一个变量$ uuid = {“ uuid”:“ 28fb72ed-0e97-4e78-9404-b676289b33ee ”};
执行后我得到的
我只需要提取28fb72ed-0e97-4e78-9404-b676289b33ee
你如何在PHP中做任何想法
我在此处包含一些代码我正在使用crcodoc查看器,并且现在已经使用crocodoc api生成了uuid来检查我分别需要uuid的状态...它传递了整个变量,我必须拆分并单独获取uuid
$ch = curl_init();
@curl_setopt($ch, CURLOPT_HEADER, 0);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'X-HTTP-Method-Override: POST'));
@curl_setopt($ch, CURLOPT_POST, 1);
@curl_setopt($ch, CURLOPT_POSTFIELDS,$param);
@curl_setopt($ch, CURLOPT_URL, $frameUrl);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$uuids = curl_exec($ch);
echo $uuids;
echo "\n\nchecking status of : ", $uuids;
$status =getStatus($uuids,$api_url,$myToken);
Run Code Online (Sandbox Code Playgroud)
可能应该在这里使用regex或explode()或implode()函数
有人可以帮忙..
谢谢
我有以下文字:
$test = 'Test This is first line
Test:123
This is Test';
Run Code Online (Sandbox Code Playgroud)
我想将此字符串分解为段落数组.我写了下面的代码,但它不起作用:
$array = explode('\n\n', $test);
Run Code Online (Sandbox Code Playgroud)
知道我在这里缺少什么吗?
你好,我有这个字符串,它是一系列代码/参考资料:
<?PHP
$list="1010<1>;1020<?>;3010<?>"; the list of items code
$id="5060<?>"; //will add this
$list_unique=explode(";", $list);
print_r($list_unique);
?>
Run Code Online (Sandbox Code Playgroud)
现在输出为:Array([0] => 1010 <1> [1] => 1020 [2] => 3010)为什么?它原因为什么?它应该是
数组([0] => 1010 <1> [1] => 1020 < ?> [2] => 3010 <?>)
简短的问题:
我想分割一个看起来像这样的标题:
$text = This is a text • and this too
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
$arry = explode('•',$text);
Run Code Online (Sandbox Code Playgroud)
但它找不到Bullet符号......所以它只返回一个包含Text的数组.我是否需要将其转换为其他格式,或者如何解决此问题?