Solved

testing first character of a string

Posted on 2008-06-16
4
209 Views
Last Modified: 2012-05-05
Hi,
I have the first  part of a date which can be = "01"

How can i test for the "0" part of the string, and if its "0" then make the string = the the second number?

I.E. If $temp = "01" then $temp = "1"

0
Comment
Question by:markmchugh
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 21793042
if ($temp[0] == '0') $temp = $temp[1];
0
 
LVL 24

Expert Comment

by:glcummins
ID: 21793056
if ('0' == substr($string, 0, 1))
{
   $string = substr($string, 1);
}
0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21793070
Try this:
if substr($temp,0) == "0" 

{

   $temp = "1"; 

}

Open in new window

0
 
LVL 6

Expert Comment

by:psychic_zero
ID: 21793209
Modified...
if substr($temp,0) == "0" 

{

   $temp = substr($temp,1); 

}

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now