WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] hep! - str_replace (2 posts)

  1. wxwx
    Member
    Posted 6 years ago #

    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?

  2. cebradesign
    Member
    Posted 6 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags