php උදවු

hirugalbandara

Well-known member
  • Sep 24, 2014
    3,705
    1,980
    113
    සිරිකොත
    මට ඕනි මේ රතු පාට තියන තැන වලට varibale එකෙක් හරහා data දෙන්ට .
    එක කරන්නනේ කොහොමද​

    උදවු කරපු කස්ටියටම පින් ,
    වැඩේ හරි ,
    Banned! ගේ විදියට වැඩ ,
    thanks .

    $body='{

    "messages":[
    {

    "a1": "94......",
    "a2": "......",
    "a3": "This is a test message",
    "a4":"abc12" }

    ]


    }';
     
    Last edited:

    Banned!

    Member
    Jun 30, 2013
    10,779
    1,070
    0
    PHP:
    $num = '';
    $message = '';
    
    $body='{
    
    "messages":[
    {
    
    "a1": "'.$num.'",
    "a2": "......",
    "a3": "'.$message.'",
    "a4":"abc12" }
    
    ]
    
    
    }';
     

    hirugalbandara

    Well-known member
  • Sep 24, 2014
    3,705
    1,980
    113
    සිරිකොත
    Oyage prashne phadili nha, hariyatama mokakda wenna one kiyanna help karannam

    machoo mata oni oya code eke thiyan than walata variable 1k haraha data denta.
    nikan "" asse data dammama wada karanawa.mata oni variable dala data denta.

    me wage.

    $abc="fhffif";

    $body='{

    "messages":[
    {

    "a1": .$abc,
    "a2": "......",
    "a3": "This is a test message",
    "a4":"abc12" }

    ]


    }';

    etha ahema dunata ganne ne.
     

    delmar

    Well-known member
  • Oct 29, 2007
    27,269
    3,863
    113
    හැමතැනම
    Mehema try karapan machan.
    puluwannam full page ekema code eka dapan.
    ethakota case eka study karala hoda uththarayak denna puluwan

    PHP:
    $a1 = "blah blah blah";
    $a2 = "dennam jambu";
    $a3 = "Elakiri.com";
    $a4 = "badagine yako";
    $body='{
    
    "messages":[
    {
    
    "a1": '. $a1 .',
    "a2": '. $a2 .',
    "a3": '. $a3 .',
    "a4": '. $a4 .'}
    
    ]
    
    
    }';
     
    Last edited:

    vdilshan

    Well-known member
  • Apr 21, 2011
    1,653
    155
    63
    Colombo, LK
    machoo mata oni oya code eke thiyan than walata variable 1k haraha data denta.
    nikan "" asse data dammama wada karanawa.mata oni variable dala data denta.

    me wage.

    $abc="fhffif";

    $body='{

    "messages":[
    {

    "a1": .$abc,
    "a2": "......",
    "a3": "This is a test message",
    "a4":"abc12" }

    ]


    }';

    etha ahema dunata ganne ne.

    PHP:
    $abc = "ABv";
    
    $body='{
    	"messages":{
    		"a1": "'.$abc.'",
    		"a2": "......",
    		"a3": "This is a test message",
    		"a4":"abc12" 
    	}
    }';
    
    // OR
    
    $myArr = array("messages" => array("a1" => $abc, "a2" => "....."));
    $myJSON = json_encode($myArr);
    
    // Test the code
    
    echo $body;
    echo "<br>";
    echo $myJSON;
    echo "<br>";
    print_r(json_decode($body));
    echo "<br>";
    print_r(json_decode($myJSON));
     
    Last edited:

    Banned!

    Member
    Jun 30, 2013
    10,779
    1,070
    0
    ohoma dunata ganne ne ban.
    man try kara,:no::no::no:

    code eka wada. I just tested., wena mokak hari aulak aththe,

    C3KhJ62.png
     
    Last edited:

    kolavari

    Well-known member
  • Aug 11, 2012
    33,746
    1
    25,655
    113
    කැළෑ පොජ්ජේ
    PHP:
    <?php
    $val1 = '94';
    $val2 = '......';
    $val3 = 'This is a test message';
    $val4 = 'abc12';
    
    $ds = [ 
        "messages" => [
            "a1" => $val1,
            "a2" => $val2,
            "a3" => $val3,
            "a4" => $val4
        ]   
    ];
    
    echo json_encode($ds);
     

    kolavari

    Well-known member
  • Aug 11, 2012
    33,746
    1
    25,655
    113
    කැළෑ පොජ්ජේ
    :lol: ලන්කන් style coding


    I'm still curious what this meant..:rolleyes: anyway, if you meant this was a bad code, remember it was intended to be understood by a newbie :yes:

    As a python dev, I highly appreciate the readability of code, so defining a json structure in a form of a string is making your code ugly and unreadable :rolleyes: You have a lot of builtin functions to work with data structures, so make the objects and arrays and use builtin functions to represent them as strings when needed...

    If you still want to use a long multi line string, I'd advice to use a heredoc to maintain the readability.

    Ex:

    PHP:
    $val1 = '94';
    $val2 = '......';
    $val3 = 'This is a test message';
    $val4 = 'abc12';
    
    $ds = <<<TEXT
    {
        "messages":[
            {
                "a1": "$val1",
                "a2": "$val2",
                "a3": "$val3",
                "a4":"$val4" 
            }
        ]   
    }
    TEXT;
    
    echo $ds;
    </div>

    Clean and Tidy ;)
     

    Sub Zer0

    Well-known member
  • Aug 11, 2015
    6,554
    2,381
    113
    I'm still curious what this meant..:rolleyes: anyway, if you meant this was a bad code, remember it was intended to be understood by a newbie :yes:

    As a python dev, I highly appreciate the readability of code, so defining a json structure in a form of a string is making your code ugly and unreadable :rolleyes: You have a lot of builtin functions to work with data structures, so make the objects and arrays and use builtin functions to represent them as strings when needed...

    If you still want to use a long multi line string, I'd advice to use a heredoc to maintain the readability.

    Ex:

    PHP:
    $val1 = '94';
    $val2 = '......';
    $val3 = 'This is a test message';
    $val4 = 'abc12';
    
    $ds = <<<TEXT
    {
        "messages":[
            {
                "a1": "$val1",
                "a2": "$val2",
                "a3": "$val3",
                "a4":"$val4" 
            }
        ]   
    }
    TEXT;
    
    echo $ds;
    </div>

    Clean and Tidy ;)

    ලන්කන් style coding
     

    Tramadol

    Well-known member
  • Jul 20, 2014
    13,396
    7,679
    113
    Kotahena
    I'm still curious what this meant..:rolleyes: anyway, if you meant this was a bad code, remember it was intended to be understood by a newbie :yes:

    As a python dev, I highly appreciate the readability of code, so defining a json structure in a form of a string is making your code ugly and unreadable :rolleyes: You have a lot of builtin functions to work with data structures, so make the objects and arrays and use builtin functions to represent them as strings when needed...

    If you still want to use a long multi line string, I'd advice to use a heredoc to maintain the readability.

    Ex:

    PHP:
    $val1 = '94';
    $val2 = '......';
    $val3 = 'This is a test message';
    $val4 = 'abc12';
    
    $ds = <<<TEXT
    {
        "messages":[
            {
                "a1": "$val1",
                "a2": "$val2",
                "a3": "$val3",
                "a4":"$val4" 
            }
        ]   
    }
    TEXT;
    
    echo $ds;
    </div>

    Clean and Tidy ;)
    Nothing is wrong with your code lol අරූ අනාථය වගේ string build කරන් කරන්න යන වැඩේ දැකල හිනා ගියා