Solved

testing first character of a string

Posted on 2008-06-16
4
211 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 count occurrences of each item in an array.

792 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