开发者

Removing the spacing from the output

开发者 https://www.devze.com 2023-02-03 10:25 出处:网络
I have this code and it works absolutely fine when I do executions of the inputs individually but when you add the inputs in a loop, theres this extra spacing gets added between the last word. I cant

I have this code and it works absolutely fine when I do executions of the inputs individually but when you add the inputs in a loop, theres this extra spacing gets added between the last word. I cant find where that is coming from.

here is the code:

function new($term)
{

    $exp = explode(" ", $term);

    so开发者_Python百科rt($exp);

    foreach($exp as $val)
    {
        echo $val;
    }

}

This basically converts "k duz q rc lvraw", into "duzklvrawqrc" only when you write new("k duz q rc lvraw")

but if I have $a = array("k duz q rc lvraw", "mybea zdr yubx xe dyroiy"); and with the code

foreach($a as $test)
{

new($test);
echo "\n";

}

The output comes out to be

"duzklvraw
qrc"

and

"dyroiy
mybeaxeyubxzdr"

This extra "\n" gets added, before the last few characters and at the end of the sentence and when you try to copy/paste it.. the lines are not consistent.

Why is this happening... this is the exact code!


"new" is a PHP keyword used for creating objects. Try using a different function name in your code.


This code shouldn't even run, since new is a keyword in PHP and cannot be used as a function name. However, if I rename new to something else, it works fine; see this example on codepad.

0

精彩评论

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

关注公众号