Another PHP problem machan :(

GT9

Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    මචන් මේ ප්‍රශ්නෙදිනම් මම මාර විදියට වැටිල ඉන්නේ. වෙනද නම් ටික වෙලාවක් දඟලල කොහොම හරි ප්‍රශ්නෙ ලිහා ගන්නව ඒත් මේක මට තාම ගොඩදාගන් බැරි උනානේ...:no::dull::baffled:
    php දන්න කොල්ලෝ එළකිරියේ ගොඩක් ඉන්නවනේ.. මේක කරන විදියට කියල දෙන්න මචන්ලා.. :)

    මට ඕන මචන්ලා function එකක් තවත් php function එකක් ඇතුලේ call කරන්න...
    මෙන්න මගේ කෝඩ් එක..
    PHP:
    <?php
    
    namePrint('Rajitha');
    
    function namePrint($name) { 
      echo $name;
    }
    
    wrap('tobaco');
    
    function wrap($txt) {
      global $name;
      echo " Your username is ".namePrint($name)." ".$txt."";
    }
    
    ?>

    මේ කෝඩ් එක run කරාම එන්නේ...

    Code:
    Rajitha Your username is tobaco

    කියලා.. ඒත් මට එන්න ඕන...

    Code:
    Rajitha Your username is Rajitha tobaco

    කියල... මේ කෙදි ප්‍රශ්නේ මචන්ලා. ඔය wrap() කියල function එක ඇතුලේ තියෙන namePrint($name) කියල කෑල්ල වැඩ කරන්නේ නැති එක.. error එකක් එන්නෙත් නෑ. මට ඕන මේ කෑල්ල කොහොම හරි වැඩ කරවගන්න.. ඒත් code structure එක වෙනස් වෙන්නත් බෑ.. මට functions හරහා.. variables වලට values assign කරන්න ඕන..

    මේ වගේ..namePrint('Rajitha'); හා wrap('tobaco');

    මේක කරගන්න විදිය කියල දෙන්න මචන්ලා ලෙකු උදව්වක්..:sorry::(:)
     

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    මචන්ලා මම කෑමට යනවා.. ඇවිල්ලා අනිවා. රිප්ලියි කරනවා..
     

    MeGusta

    Banned
    Sep 11, 2012
    10,585
    512
    0
    <?php
    namePrint('Gusta');

    function namePrint($name) {
    echo $name;
    }

    wrap('Me Gusta');

    function wrap($txt) {
    global $name;
    echo " Your username is ".nameprint($name).$txt."";
    }
    ?>

    Gusta Your username is Me Gusta


    :rofl:sry ban man danne...somebody help him
     

    Lalakajee

    Well-known member
  • Jun 20, 2007
    3,061
    296
    83
    In my own heart
    PHP:
    echo namePrint('Rajitha');
    
    function namePrint($name) { 
      return $name;
    }
    
    wrap('tobaco');
    
    
    
    function wrap($txt) {
      $name = 'Rajitha';
      echo " Your username is ".namePrint($name)." ".$txt."";
    }

    Code:
    Rajitha Your username is Rajitha tobaco
     
    Last edited:

    OnDaRock

    Well-known member
  • Feb 21, 2010
    938
    610
    93
    PHP:
    <?php 
    
    namePrint('Rajitha'); 
    
    function namePrint($name) {  
      echo $name; 
    } 
    
    wrap('tobaco'); 
    
    function wrap($txt) { 
      global $name; 
      echo $name; //meka mukuth enne nehe 
      echo " Your username is ".namePrint($name)." ".$txt.""; 
    } 
    
    ?>

    methana machan $name eka wrap eka ethule nehe. palleha thiyena daala balapan ethakota wenda one de wenawa neda ??

    PHP:
    <?php 
    
    namePrint('Rajitha'); 
    
    function namePrint($name) {  
      echo $name; 
    } 
    
    wrap('tobaco'); 
    
    function wrap($txt) { 
      global $name; 
      echo $name;
      echo " Your username is ".namePrint(' dunndana pola')." ".$txt.""; 
    } 
    
    ?>

    machan umbata karanna one de hariyatama kiyapan ....
     

    Ayeshlive

    Well-known member
  • Jul 1, 2011
    10,570
    943
    113
    *̶͑̾̾​̅ͫ͏̙̤g͛͆̾ͫ̑͆&
    මචන් ඔය ඔතන function එක ඇතුලේ echo කරනවා. ඒ නිසා PHP කරන්නේ ඉස්සරලා name එක print කරන එක. echo එකේ return එකක් නෑ.

    අනිත් එක global keyword එක use කරන්න කලින් ඒක global scope ekema define කරලා තියෙන්න ඕනේ me widihata:
    http://3v4l.org/9EsTb
    PHP:
    <?php
    function set_name($name) {
      $GLOBALS['name'] = $name;
    }
    
    function get_name() {
      return $GLOBALS['name'];
      /* Above line is equal to:
       * global $name;
       * return $name;
       */
    }
    
    function wrap($txt) {
      echo 'Your username is ' . get_name() . ' ' . $txt;
    }
    
    /* You should not print/echo stuff in a function. So the better way would be:
     * function wrap($txt) {
     *  return  'Your username is ' . get_name() . $txt;
     * }
     * echo wrap($txt)
     */
    
     
    // Usage:
    
    set_name('Rajitha');
    wrap('tobacco');
    ?>
     
    Apr 30, 2012
    583
    40
    0
    <?php



    function namePrint($name) {
    return $name;
    }

    wrap('tobaco');

    function wrap($txt) {
    echo " Your username is ".namePrint('Rajitha')." ".$txt."";
    }

    ?>
     

    nismok

    Well-known member
  • Jun 27, 2008
    9,377
    672
    113
    :nerd:

    Code:
    <?php
    $myName = 'Rajitha';
    
    function namePrint($name) {  
    	[B]return $name;[/B]
    }
    
    function wrap($text, $name) {
    	return 'Your username is '.namePrint($name).' '.$text;
    }
    
    echo wrap('tobaco', $myName);
    ?>
     

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    monada bn me
    PHP :D


    THANKS NUWAN AIYA :)

    <?php
    namePrint('Gusta');

    function namePrint($name) {
    echo $name;
    }

    wrap('Me Gusta');

    function wrap($txt) {
    global $name;
    echo " Your username is ".nameprint($name).$txt."";
    }
    ?>

    Gusta Your username is Me Gusta


    :rofl:sry ban man danne...somebody help him

    :D අවුලක්නෑ මී ගුස්ටා.. රිප්ලයි එක වටිනවා.:cool:

    :rofl:

    bump boss
    තෑන්ක්ස් බොස්..:cool:

    PHP:
    echo namePrint('Rajitha');
    
    function namePrint($name) { 
      return $name;
    }
    
    wrap('tobaco');
    
    
    
    function wrap($txt) {
      $name = 'Rajitha';
      echo " Your username is ".namePrint($name)." ".$txt."";
    }

    Code:
    Rajitha Your username is Rajitha tobaco

    මේ විදිය හරි යන්නෑ මචන්.. wrap function එක ඇතුලේ $name වේරියබල් එකට වැලුයිස් අසයින් කරල බෑ.. මගේ කෝඩ් එකේ හැටියට... රිප්ලයි එකට තෑන්ක්ස් මචන්..:)

    PHP:
    <?php 
    
    namePrint('Rajitha'); 
    
    function namePrint($name) {  
      echo $name; 
    } 
    
    wrap('tobaco'); 
    
    function wrap($txt) { 
      global $name; 
      echo $name; //meka mukuth enne nehe 
      echo " Your username is ".namePrint($name)." ".$txt.""; 
    } 
    
    ?>

    methana machan $name eka wrap eka ethule nehe. palleha thiyena daala balapan ethakota wenda one de wenawa neda ??

    PHP:
    <?php 
    
    namePrint('Rajitha'); 
    
    function namePrint($name) {  
      echo $name; 
    } 
    
    wrap('tobaco'); 
    
    function wrap($txt) { 
      global $name; 
      echo $name;
      echo " Your username is ".namePrint(' dunndana pola')." ".$txt.""; 
    } 
    
    ?>

    machan umbata karanna one de hariyatama kiyapan ....

    මචන්..namePrint(' dunndana pola') විදියට වැලියුස් අසයින් කරල බෑ මචන්.. auto ගන්න විදියට හදන්න ඕන.. රිප්ලයි එකට ගොඩක් තෑන්ක්ස්.. මම ට්‍රයි කරල කරල එපා වෙලා. මුලු කෝඩ් එකම වෙනස් විදියකට වෙනස් කරල.. වැඩේ කර ගත්ත..:)

    මචන් ඔය ඔතන function එක ඇතුලේ echo කරනවා. ඒ නිසා PHP කරන්නේ ඉස්සරලා name එක print කරන එක. echo එකේ return එකක් නෑ.

    අනිත් එක global keyword එක use කරන්න කලින් ඒක global scope ekema define කරලා තියෙන්න ඕනේ me widihata:
    http://3v4l.org/9EsTb
    PHP:
    <?php
    function set_name($name) {
      $GLOBALS['name'] = $name;
    }
    
    function get_name() {
      return $GLOBALS['name'];
      /* Above line is equal to:
       * global $name;
       * return $name;
       */
    }
    
    function wrap($txt) {
      echo 'Your username is ' . get_name() . ' ' . $txt;
    }
    
    /* You should not print/echo stuff in a function. So the better way would be:
     * function wrap($txt) {
     *  return  'Your username is ' . get_name() . $txt;
     * }
     * echo wrap($txt)
     */
    
     
    // Usage:
    
    set_name('Rajitha');
    wrap('tobacco');
    ?>

    ගොඩක් ස්තුතියි මචන් රිප්ලයි එකට.. ඔයා නිසා.. functions ඇතුලෙ echo, print use කරන එක හොඳ ප්‍රැක්ටිස් එකක් නෙමෙයි කියල ඉගෙන ගත්ත.. මේ කෝඩ් එකත් මචන් මම ට්‍රයි කරා. නමුත්..මුලින්.. Rajitha කියල මේකේ ප්‍රින්ට් වෙන්නෑ. :( අවුලක් නෑමචන්..මම මුලු කෝඩ් එකම අලුතෙන් ලිව්ව... දැන් වෙනස්ම විදියකට වැඩ..:)
     

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    machanla matath php igenaganna oni.onln tutorial tikak ganna puluwan tanak danawada

    මම මචන් ‍ඔක්කොම ඉගෙන ගත්තේ වෙබ් එකෙන් තමයි. youtube, ebooks, forums...etc :)

    <?php



    function namePrint($name) {
    return $name;
    }

    wrap('tobaco');

    function wrap($txt) {
    echo " Your username is ".namePrint('Rajitha')." ".$txt."";
    }

    ?>
    තෑන්ක්ස් මචන් රිප්ලයි එකට.. මේකේ මචන් මුලින් Rajitha කියන එක ප්‍රින්ට් වෙන්නෑනේ... මේක කරන්න බෑ වගේ මචන්..මම කරන්න පුලුවන් හැම දේම කරා.. මේ වගේ දෙයක් කරන්න php built-in functions තියෙනවද කියලනම් දන්නෑ...

    :nerd:

    Code:
    <?php
    $myName = 'Rajitha';
    
    function namePrint($name) {  
    	[B]return $name;[/B]
    }
    
    function wrap($text, $name) {
    	return 'Your username is '.namePrint($name).' '.$text;
    }
    
    echo wrap('tobaco', $myName);
    ?>

    මචන් මට ඕන variable value eka function parameter එකක් විදියට එවන්.. ඒනිසා මේ ක්‍රමේ හරියන්නෑ... BTW thanks for the comment :)

    ko bola maykey return 1a..?
    first function 1y return 1a liyapun
    thanks machan :)

    bump thama machan

    awlak naa machan bump ekath loku help ekak :D
     

    rooshan2008

    Well-known member
  • Apr 16, 2008
    5,896
    1,271
    113
    CALL 0x754EA
    PHP:
    <?php
    function namePrint($n){
        global $name;
        $name = $n;
        echo $n;
    }
    
    function wrap($txt) {
        global $name;
        echo " Your username is ";
        namePrint($name);
        echo " ".$txt;
    }
    
    $name;
    namePrint('Rajitha');
    wrap('tobaco');
    
    ?>
     
    • Like
    Reactions: GT9

    GT9

    Well-known member
  • Jun 22, 2013
    1,564
    167
    63
    [email protected]
    PHP:
    <?php
    function namePrint($n){
        global $name;
        $name = $n;
        echo $n;
    }
    
    function wrap($txt) {
        global $name;
        echo " Your username is ";
        namePrint($name);
        echo " ".$txt;
    }
    
    $name;
    namePrint('Rajitha');
    wrap('tobaco');
    
    ?>

    ඔහ් මචන්... පට්ට අහ්!...සුපිරි.. වැඩේ හරි..මචන්.. මම මේකත් එක්ක කොච්ර වෙලා දැඟුලුවද :baffled::rofl: ඒත් ඔයා පොඩි වෙලාවෙන් මම අහපු ගැටලුව තේරුම් අරගෙන මට ඕන විදියටම කෝඩ් එක ලියල තියෙනව.. සුපිරියට වැඩ කරනව මචන් කෝඩ් එක.. මම කෝඩ් එක වෙනස් කරල වෙන විදියකට කර ගත්ත.. ඒත් මේ කෝඩ් එක බලල මම දැනගත්ත මේ වගේ අවස්තාවක කොහොමද කෝඩ් එක ලියන්නේ කොහොමද කියල.. ගොඩක් ස්තුතියි මචන්.. ඔයානම් පට්ටම පට්ට වැඩ කාරයෙක්. මේ කරන උදව් වලට ගොඩක් පින්...:) ඔයා වගේ අමතර variables ටිකක් පාවිච්චි කරල මේ වැඩේ කරගන්න මට ඔලුවට ආවේ නෑනේ.. :dull:

    PHP:
    <?php
    // $name;
    namePrint('Rajitha');
    wrap('tobaco');
    
    function namePrint($n){
        global $name;
        $name = $n;
        echo $n;
    }
    
    function wrap($txt) {
        global $name;
        echo " Your username is ";
        namePrint($name);
        echo " ".$txt;
    }
    ?>

    thanks :)