[HELP] How to get text string encapsulated within special characters?

Discussion in 'PHP' started by farhan91, Sep 26, 2010.

  1. #1
    Hey, does anyone know how I can get a text string encapsulated within a special character?

    Example:
    $_mytext = "|text1|text2|text3|";

    I want to be able to print a list like this:

    1. text1
    2. text2
    3. text3

    Please and thanks :)
     
    farhan91, Sep 26, 2010 IP
  2. xrvel

    xrvel Notable Member

    Messages:
    918
    Likes Received:
    30
    Best Answers:
    2
    Trophy Points:
    225
    #2
    Try this :)

    <?php
    $_mytext = "|text1|text2|text3|";
    $_mytext = trim($_mytext, '|');
    $arr = explode('|', $_mytext);
    if ($arr != array()) {
    	echo '<ol>';
    	foreach ($arr as $a) {
    		echo '<li>'.$a.'</li>';
    	}
    	echo '</ol>';
    }
    ?>
    PHP:
     
    xrvel, Sep 26, 2010 IP
  3. farhan91

    farhan91 Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    WOW, that worked perfectly! :)

    Thanks soo much for your help :)
     
    farhan91, Sep 26, 2010 IP