abdelelbouhy Posted November 14, 2010 Share Posted November 14, 2010 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 More sharing options...
abdelelbouhy Posted November 14, 2010 Author Share Posted November 14, 2010 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 helpsorted i moved the code to another file and used highlight_file() Link to comment Share on other sites More sharing options...
birbal Posted November 14, 2010 Share Posted November 14, 2010 sorry i thought its a double quote. my mistake.post edited. Link to comment Share on other sites More sharing options...
Dilated Posted November 14, 2010 Share Posted November 14, 2010 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 codeI'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 More sharing options...
justsomeguy Posted November 14, 2010 Share Posted November 14, 2010 You can also just break up the PHP tags: <?php $code = " <" . "?php...?" . ">"; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.