只删除字符串中的国家/地区代码而不是斜杠

I want to remove only country code not slash from string .

suppose: phone number is +1-555-555-5555 and i want like 555-555-5555

My code is

<?php 
$sPhoneNumber =get_post_meta($post_id, '_vfb_field-23', true);
echo $result = preg_replace("/[^0-9]/", "", $sPhoneNumber);
?>

it given me output like 15555555555 and i want 555-555-5555

Use the following regex substitution:

$result = preg_replace("/^\+\d+-/", "", $sPhoneNumber);

It will remove 1+ digits and a - after it from the start of a string.

Using this solution, you will avoid changing strings that do not start with + followed with digits.

Instead of \d+ you may specify the country codes you need to remove. Say, you need to remove 22 and 48 codes:

$result = preg_replace("/^\+(?:48|22)-/", "", $sPhoneNumber);

You can use substr to get the substring after first '-', live demo here.

substr($string, strpos($string, '-') + 1);

Please refer : Working Demo

<?php
$phonenumber = '+1-555-555-555';
$array = explode("-", $phonenumber,2);
echo $array['1'];
?>

For more details PHP EXPLODE

Try this, use preg_replace for it,

$result = preg_replace('~^[0\D]++|\D++~', '', $sPhoneNumber);

DEMO

try on this site http://www.phpliveregex.com/p/jXB this reg

[^\+[0-9]-].*

using this function

preg_match("/[^\+1-].*/", $input_line, $output_array);

so basic you gonna find all the is not "+1-"

Its very simple, we can use substr() function to cut portion of string.

<?php
echo substr("+1-555-555-5555",3);
?>

Here's a link PHP substr()