Solved

testing first character of a string

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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…
The viewer will learn how to count occurrences of each item in an array.

813 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

18 Experts available now in Live!

Get 1:1 Help Now