开发者

PHP String Variable

Cand we apply php constructs, and logic inside php string variable.... like

// php string variable:

$content = "Somethin开发者_如何学Pythong in string........bla bla bala.......".
 while(.....){}
 ."agian string...";

echo $content;


// i am getting error => unexpected T_WHILE in my php....


No, you can't. But you can use a function :

function myFunction() {
    while(....) {
        ...
    }
    return $something;
}
$content = "Something in string........bla bla bala......." . myFunction() . "agian string...";
echo $content;


No. No, you can't.

Use string concatenation properly:

$content = "Start";
while (<something>) {
   $content .= "Middle";
}
$content .= "End";


No you can't do that but you could do this.

$content = "Something in string........bla bla bala.......";
while(.....){
    $content .= "agian string...";
}

echo $content;


No. You'll have to append in a loop:

$content = "Something in string........bla bla bala.......";
while ($i++ < 20) {
    $content .= 'something else';
}
$content .= 'something to end';

echo $content;


Don't know, what the while(...)-part should do, but implode() may help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜