PHP:为什么回显相同字符串的两个代码会返回不同的结果?

I'm new at PHP and I don't understand why this happens.I try using echo to show "$imglinksis" and the result is exactly http://catpic.s3.amazonaws.com/product.jpg

I do not understand why the 2nd Code fails. Please help!

Code #1: This code completely works in returning the fields I want

        <?php function CallCatpicAPI($photoUrl){do something...}

$imglinksis = "http://catpic.s3.amazonaws.com/product.jpg";
$jsonReturnCatpic = CallCatpicAPI($imglinksis);?>

Code #2: Fail to return: API says invalid URL image link

        <?php function CallCatpicAPI($photoUrl){do something...}?>

        <script>var img_link = "http://catpic.s3.amazonaws.com/product.jpg";</script>

<?php
$imglinksis = "<script>document.write(img_link).toString()</script>";
$jsonReturnCatpic = CallCatpicAPI($imglinksis);?>

You are mixing the two codes. Your php is executed on the server but the javascript is executed on the client side after php executed. You can fix your second code by this:

     <?php 
        $imglinksis = 'http://catpic.s3.amazonaws.com/product.jpg';
        function CallCatpicAPI($photoUrl){do something...} 
     ?>

    <script>var img_link = '<?php echo $imglinksis; ?>';</script>

    <?php
        $jsonReturnCatpic = CallCatpicAPI($imglinksis);
    ?>