Jump to content

ouput php code


abdelelbouhy

Recommended Posts

hello guysi'm trying to output php code using highlight_string() and i got this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\index.php on line 113here is the code<?php $code = " <?php $user = 'root'; $password = ''; $dsn = 'mysql:host=localhost;dbname=world;'; $country = $_GET['country'] ? $_GET['country'] : 'USA'; $country = strtoupper($country); try{ $dbh = new PDO($dsn,$user,$password); $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $sql ='Select * from city where CountryCode =:country'; $stmt = $dbh->prepare($sql); $stmt->bindParam(':country',$country,PDO::PARAM_STR); $stmt->execute(); $i =0 ; while($row = $stmt->fetchObject()){ $i++; echo '<tr>'; echo '<td>' . $row->Name . '</td>' . '<td>' . $row->CountryCode . '</td>' . '<td>' . $row->Population . '</td>'; echo '</tr>'; if($i == 10){ break; } } }catch(PDOException $e){ echo $e->getMessage(); echo $e->getCode(); } ?> "; highlight_string($code); ?>please help

Link to comment
Share on other sites

hello guysi'm trying to output php code using highlight_string() and i got this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\index.php on line 113here is the code<?php $code = " <?php $user = 'root'; $password = ''; $dsn = 'mysql:host=localhost;dbname=world;'; $country = $_GET['country'] ? $_GET['country'] : 'USA'; $country = strtoupper($country); try{ $dbh = new PDO($dsn,$user,$password); $dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $sql ='Select * from city where CountryCode =:country'; $stmt = $dbh->prepare($sql); $stmt->bindParam(':country',$country,PDO::PARAM_STR); $stmt->execute(); $i =0 ; while($row = $stmt->fetchObject()){ $i++; echo '<tr>'; echo '<td>' . $row->Name . '</td>' . '<td>' . $row->CountryCode . '</td>' . '<td>' . $row->Population . '</td>'; echo '</tr>'; if($i == 10){ break; } } }catch(PDOException $e){ echo $e->getMessage(); echo $e->getCode(); } ?> "; highlight_string($code); ?>please help
sorted i moved the code to another file and used highlight_file()
Link to comment
Share on other sites

sorry i thought its a double quote. my mistake.post edited.

Link to comment
Share on other sites

hello guysi'm trying to output php code using highlight_string() and i got this error Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\index.php on line 113here is the code
I'm confused because I don't see anywhere close to 113 lines in that code. Maybe that file is being included in another file which is causing the error? Anyway, try using a heredoc instead.
<?php   $code = <<<CODE<?php   etc etc?>CODE;   highlight_string($code);?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...