We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,194 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to Add a + sign to a string in php

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
Thanks

4
Contributors
3
Replies
2 Hours
Discussion Span
5 Months Ago
Last Updated
5
Views
DaveyMoyes
Junior Poster
122 posts since May 2009
Reputation Points: 9
Solved Threads: 0
Skill Endorsements: 0

You should just be able to do this:

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

GliderPilot
Posting Whiz in Training
239 posts since Sep 2006
Reputation Points: 34
Solved Threads: 42
Skill Endorsements: 12

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.

gavinflud
Light Poster
46 posts since Dec 2012
Reputation Points: 14
Solved Threads: 9
Skill Endorsements: 0

@DaveyMoyes

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 );
LastMitch
Industrious Poster
4,177 posts since Mar 2012
Reputation Points: 132
Solved Threads: 335
Skill Endorsements: 45

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.1182 seconds using 2.96MB