SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2003
    Location
    Toronto, Ontario
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Check (if . exists) and Remove?

    Hey guys,

    I was just trying to figure out how...

    Check if a variable contains a . in it. Then remove everything after that dot.

    Any help, or a point in the right direction would be appreciated.

    Thanks,
    Mario
    $ Available For Hire
    Need a website designed or coded? Then feel free to contact me!

    PSP Backgrounds - PSPBG.net || Photoshop Brushes - PSBrushes.net

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    16 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    $str 'xewdwe dfew .fwefwef we f we f we .f wef';

    $pos strpos($str,'.');
    if(
    $pos!==false) {
        
    $str substr($str,0,$pos);
    }

    echo 
    '<p>',$str,'</p>'

  3. #3
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    oddz' code works well. You could also use the following which should also do the trick.

    PHP Code:
    $str 'xewdwe dfew .fwefwef we f we f we .f wef';
    $str strtok($str'.');
    echo 
    '<p>'$str'</p>'
    Salathe
    Software Developer and PHP Manual Author.


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
  •