1,105,380 Community Members

How to Add a + sign to a string in php

Member Avatar
Junior Poster
122 posts since May 2009
Reputation Points: -1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

Hi Everyone,
How can I add a + sign to the following string.... for some reason I just can not figure it out
I have tried ".+
and ".+."
and sign quotes - both options but it just doesnt seem to work for me....

$number = $Code."".substr( $mobnum, 0 );

So, number will be the international code of the country plus the sms text message
for example 4401234567890 for UK numbers
but for international numbers I am trying to add the + sign
So it reads +11234567890 for the US...

Hope someone can help & explain where I am going wrong

Member Avatar
Posting Whiz in Training
296 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 49 [?]
Skill Endorsements: 14 [?]

You should just be able to do this:

$number = '+' . $Code."".substr( $mobnum, 0 );

Member Avatar
Light Poster
46 posts since Dec 2012
Reputation Points: 14 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 0 [?]

If you're just looking to add a plus sign at the beginning of a sequence of numbers, then it's as simple as the following:

$number = 1234567890;
$complete_number = "+" . $number;

Just ensure the + sign is inside the quotation marks.

Sorry if that's not what you're looking for, it's hard to tell from your code since I don't know the values of the variables.

Deleted Member


Hope someone can help & explain where I am going wrong

You didn't do anything wrong. It's just that + sign is to used for international call. It's pretty expensive.

Instead of this ".+ or this ".+." used "{+}"

Try this:

    $number = $Code."{+}".substr( $mobnum, 0 );
This article has been dead for over three months: Start a new discussion instead
Start New Discussion
View similar articles that have also been tagged: