Ajax jQuery
Ajax jQuery

Reputation: 345

Creating an HTML page from PHP

So I'm creating new HTML pages using PHP and I'm running into a problem.

<?php
$filecreate = $fopen("yo.html","w");
fwrite($filecreate,"<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://apis.google.com/js/client.js?onload=onJSClientLoad"></script>
....... </html>")
?>

It seems like It's maybe grabbing one of the quotes from the <script src= tag and ending it early. How would I get around this issue?

Upvotes: 0

Views: 74

Answers (2)

Peter Manoukian
Peter Manoukian

Reputation: 158

        <?php
        $filecreate = $fopen("yo.html","w");
        fwrite($filecreate,"<html>
        <script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\"></script>
        <script src=\"http://apis.google.com/js/client.js?onload=onJSClientLoad \"></script>
        ....... </html>")
        ?>

You have started a quote " and added another " on script, you should escape them

Upvotes: 0

xlecoustillier
xlecoustillier

Reputation: 16351

You have to escape the character you use as a string delimiter in the content of your string. The syntax highlighter in your IDE shows you that something's wrong.

Replace your double quotes inside your string with simple quotes, or escape them.

fwrite($filecreate,"<html>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src='http://apis.google.com/js/client.js?onload=onJSClientLoad'></script>
....... </html>")

or

fwrite($filecreate,"<html>
<script src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js\"></script>
<script src=\"http://apis.google.com/js/client.js?onload=onJSClientLoad\"></script>
....... </html>")

Upvotes: 3

Related Questions