[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Split string after first character

Posted on 2009-02-16
8
Medium Priority
?
370 Views
Last Modified: 2013-12-06
Dear Experts,

How do I split a string after the first character?

If I have

$mystring = "this is my string"

I want to end up with

$string_one = "t"'
$string_two = "his is my string"'

Thanks
0
Comment
Question by:narmi2
  • 5
  • 3
8 Comments
 
LVL 8

Expert Comment

by:isaackhazi
ID: 23650036
$string="this is my string"
$string_1=substr($string,0,1);
echo $string;

0
 
LVL 1

Author Comment

by:narmi2
ID: 23650050
What about string_two?
0
 
LVL 8

Expert Comment

by:isaackhazi
ID: 23650060
$string_one = "this is my string"
$string_two =substr($string_one,0,1);

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:narmi2
ID: 23650076
string one should only have "t"
string two should have the full string minus "t" for example "his is my string".
0
 
LVL 8

Expert Comment

by:isaackhazi
ID: 23650156
make three strings

$string_one = "this is my string"
$string_two =substr($string_one,0,1);
$stiring_three=substr($string_one,1,16);
0
 
LVL 8

Accepted Solution

by:
isaackhazi earned 2000 total points
ID: 23650167
if you are unsure of the lenght of the string

$string_one = "this is my string"
$string_two =substr($string_one,0,1);
$stiring_three=substr($string_one,1,strlen(string_one));
0
 
LVL 8

Expert Comment

by:isaackhazi
ID: 23650173
i hope you get the idea...

cheers
0
 
LVL 1

Author Comment

by:narmi2
ID: 23650176
The original string was just an example, it can be of any length, so a cannot use the fixed length of 16 to get string three in your example.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 3 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question