Support » Fixing WordPress » hep! – str_replace

  • Resolved wxwx

    (@wxwx)


    Hey

    I’m working on cformsll. maybe you can help me how to figure this thing.

    add_post_meta($ppost_id, 'externalpost', str_replace("\n",'<br />',$form['externalpost']));

    the result will be

    hello
    hello
    hello

    i want to make it to be

    <li>hello</li>
    <li>hello</li>
    <li>hello</li>

    Any clues?

Viewing 1 replies (of 1 total)
  • I was looking for a solution for for the same problem, and found one that helped me, I hope it can help you.

    In this forum, I found this piece of code:

    function dostuff($str) {
    return "<ul>" . preg_replace(array("/^\s+/s", "/(.*?)(\r?\n)+/gs"), array("", "<li>$1</li>"), $str . "\r\n") . "</ul>";
    }

    I think you could write something like:

    add_post_meta($ppost_id, 'externalpost', preg_replace(array("/^\s+/s", "/(.*?)(\r?\n)+/gs"), array("", "<li>$1</li>"), $str . "\r\n"));

    I hope this would be useful!

Viewing 1 replies (of 1 total)
  • The topic ‘hep! – str_replace’ is closed to new replies.