如何在php中的两个变量中拆分斜杠/分隔的字符串

时间:2015-06-19 02:24:20

标签: php

假设申请人ID是从另一个表单传递的。我有来自我的数据库的数组变量,这里是代码:

$array_id_applicants = explode(";",stripslashes($applicant_id1));
$applicants_num = count($array_id_applicants);
$arr_app_num = array();
for($x=0;$x<=$applicants_num;$x++) 
{ 
if($array_id_applicants[$x]){
 $applicant_id = str_replace("'","",$array_id_applicants[$x]);

 $applicants = getdata("select cellphone from personal where applicant_id='".$applicant_id."'");
$replace_array = array("-","(",")","+","_");
array_push($arr_app_num,str_replace($replace_array,"",$applicants[1][cellphone]));
 }
}
$applicant_number = implode(";",$arr_app_num);
echo $applicant_number; exit;

假设这是数组的值:

$applicant_number = '639152478931 / 631687515455','631235497891'

我希望输出如下:

$applicant_number = '639152478931','631687515455','631235497891'

2 个答案:

答案 0 :(得分:1)

看看这是否是你想要做的。:

function naturalCompare(a, b) {
    var ax = [], bx = [];

    a.replace(/(\d+)|(\D+)/g, function(_, $1, $2) { ax.push([$1 || Infinity, $2 || ""]) });
    b.replace(/(\d+)|(\D+)/g, function(_, $1, $2) { bx.push([$1 || Infinity, $2 || ""]) });

    while(ax.length && bx.length) {
        var an = ax.shift();
        var bn = bx.shift();
        var nn = (an[0] - bn[0]) || an[1].localeCompare(bn[1]);
        if(nn) return nn;
    }

    return ax.length - bx.length;
}

var nrArray = nrArray.sort(naturalCompare);

给你:

<?php
    $applicant_number[] = '639152478931 / 631687515455';
    $applicant_number[] = '631235497891';
    $applicant_number[] = '0294765388389 / 52525252525';
    $applicant_number[] = '0012324252728';

    $new    =   array();

    foreach($applicant_number as $number) {
            if(strpos($number,'/') !== false) {
                    $val    =   explode("/",str_replace(" ","",$number));
                    $new    =   array_merge($new,$val);
                }
            else
                $new[]  =   $number;
        }

    print_r($new);
?>

答案 1 :(得分:0)

@Path("/your/path")
public class ExternalServiceResource {

    private final HttpClient client;

    public ExternalServiceResource(HttpClient client) {
        this.client = client;
    }

    @GET
    public String doStuff() {
        return /* use client to make some call */;
    }
}

给你:

数组([0] =&gt; +639152478931 [1] =&gt; +631235497891 [2] =&gt; +634765388389 [3] =&gt; +632324252728)