Solved

testing first character of a string

Posted on 2008-06-16
4
213 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

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.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.

688 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