SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $part = "01";
    echo "<p>part = $part";
    if (ereg ("^0", $part)) {
    	ereg_replace ("^0","", $part);
    }
    echo "<p>revised part = $part";
    Output:

    > part = 01
    > revised part = 01

    Any idea why this is not working?

    TIA,
    Mike

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is because you have not assigned the result of the ereg_replace to a var to make your code work
    Code:
    $part = "01";
    echo "<p>part = $part";
    if (ereg ("^0", $part)) {
    	$part = ereg_replace ("^0","", $part);
    }
    echo "<p>revised part = $part";
    Although since ereg() is so slow I would suggest this approach.

    Code:
    $part = "01";
    echo "<p>part = $part";
    if (substr($part, 0, 1) == 0) {
    	$part = substr($part, 1, strlen($part));
    }
    echo "<p>revised part = $part";
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •