Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2006
    Location
    Kepler 62f
    Posts
    16,703

    Remove everything after punctuation in php?

    Let's say I have:
    John likes bananas, apples and oranges

    What I want is:
    John likes bananas

    Everything after the , is removed.

    I'm currently starting with this one snippet of code in WordPress:

    Code:
    <?php echo get_the_term_list($post->ID, TAXONOMY_NAME, ' ', ', ', ''); ?>
    Right now, it shows the whole custom name. I want to shorten it when displayed.

    How can I alter this one piece of code to do that?
    || Need a good host?
    || See my Suggested Hosts List || Editorial: EIG/Site5/Arvixe/Hostgator Alternatives
    ||

  2. #2
    Join Date
    Feb 2006
    Location
    Kepler 62f
    Posts
    16,703
    This may be what I need, but having a hard time isolating the exact syntax needed:
    http://stackoverflow.com/questions/1...er-a-character
    || Need a good host?
    || See my Suggested Hosts List || Editorial: EIG/Site5/Arvixe/Hostgator Alternatives
    ||

  3. #3
    Join Date
    Oct 2004
    Location
    Celebration, Florida
    Posts
    209
    $phrase = "John likes apples, oranges and bananas.";
    $separate = explode(",",$phrase);
    echo $separate[0];
    Richard C. Hay - Celebration, Florida
    Web Application Development, Graphic Design & Organization Management Services

  4. #4
    Join Date
    Feb 2006
    Location
    Kepler 62f
    Posts
    16,703
    But how do I integrate it into the above snippet of code?
    That's where I'm stuck.
    || Need a good host?
    || See my Suggested Hosts List || Editorial: EIG/Site5/Arvixe/Hostgator Alternatives
    ||

  5. #5
    Join Date
    Jul 2009
    Location
    NC
    Posts
    938
    Code:
    <?php
    
    $phrase = get_the_term_list($post->ID, TAXONOMY_NAME, ' ', ', ', '');
    $separate = explode(",",$phrase);
    echo $separate[0];
    
    ?>
    ☆☆☆ Cool Domain Names - DomainSale.link☆☆☆

  6. #6
    Join Date
    Feb 2006
    Location
    Kepler 62f
    Posts
    16,703
    No, something odd is still going on there. It crashes the page.

    I'm just to to give up on this one. I can make another custom field instead, and use it for displaying the shorter text.

    Thanks, though.

    At least I know it's not just me. Nobody can seem to get this working.
    || Need a good host?
    || See my Suggested Hosts List || Editorial: EIG/Site5/Arvixe/Hostgator Alternatives
    ||

Similar Threads

  1. PHP to remove .com from name?
    By kpmedia in forum Programming Discussion
    Replies: 4
    Last Post: 09-20-2014, 06:39 PM
  2. How to remove php
    By dtommy79 in forum VPS Hosting
    Replies: 6
    Last Post: 04-06-2010, 07:17 AM
  3. Test your punctuation
    By The Dude in forum Web Hosting Lounge
    Replies: 15
    Last Post: 09-22-2009, 02:28 PM
  4. deleting punctuation and special chars
    By michael-lane in forum Programming Discussion
    Replies: 3
    Last Post: 02-17-2006, 07:42 PM
  5. PHP Need to remove a . ?
    By AskAR in forum Programming Discussion
    Replies: 9
    Last Post: 12-01-2005, 07:07 PM

Posting Permissions

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