PHP problem, help me...

Jecob Boman

Well-known member
  • Dec 10, 2013
    1,333
    93
    48
    homagama
    මචංලා මට අදත් පොඩි php අවුලක් තියෙනවා. මෙන්න මේ පහත තියෙන කෝඩ් එක පොඩ්ඩක් බලන්නකෝ.
    PHP:
    <?php
    
    // Get mysql database data(with \n).
    $str_in = 
    'one
    two
    three
    
    fore
    five
    
    six
    ';
    
    // Convert \n into <br>.
    $str = $str_in;
    
    // Explode $str and wrapped into <p> tags.
    $str_exploded = explode("\n\n",$str);
    
    foreach($str_exploded as $sub_str) {
    
    	echo '<p>'.$sub_str.'</p>';
    
    }    
    
    ?>

    මේක රන් කරාම ලැබෙන්නේ මෙන්න මේ වගේ Output එකක් බන් :( :( :(

    Code:
    <p>one<br>
    two<br>
    three<br>
    <br>
    fore<br>
    five<br>
    <br>
    six<br>
    </p>

    ඒත් මට ඕන මෙන්න මේ වගේ Output එකක් එන්න :yes::yes::yes:

    Code:
    <p>one<br>
    two<br>
    three</p>
    
    <p>fore<br>
    five</p>
    
    <p>six</p>

    මම මචන් මේක කරන්න regular expressions භාවිතා කරන්න කැමති නෑ. :no: මෙකද මේ script එක run වෙන්නේ loop එකක් ඇතුලේ. එතකොට ලොකු perfomance අඩු වීමක් වෙයි කයල බයයි. මේක කරගන්න සෙට් වෙන php function  එකක් නැද්ද මචංලා. :confused:

    ‍ලොකු උදව්වක් මේක ගොඩ දාගන්න හෙල්ප් එකක් දුන්නොත්.

    තෑන්ක්ස් JB :D