I downloaded geshi in the geshi folder from the root directory and I tried to use the example: // // Include the GeSHi library// include_once 'geshi/geshi.php'; //// Define some source to highlight, a language to use // and the path to the language files// $source = '$foo = 45; for ( $i = 1; $i < $foo; $i++ ){ echo "$foo\n"; --$foo; }'; $language = 'geshi/php.php'; // // Create a GeSHi object// $geshi = new GeSHi($source, $language); // // And echo the result!// echo $geshi->parse_code(); PHP: but I get only this without color. Please, can anyone tell me what I did wrong?
Yes, with the example from their site, but if I put my code, I get this error . What do you think ? This is my code, without the html header : <?php // Include the GeSHi library// include_once 'geshi.php'; //// Define some source to highlight, a language to use // and the path to the language files// $source = '<?php include_once("mysql_connect.php"); if(isset($_POST['submit'])){ $problem = FALSE; if(empty($_POST['search'])){ $problem = TRUE; echo "<p style=\"color:#FF0000;\">Please enter a search term!</p>"; } if(!$problem){ $text = $_POST['search']; $query = "SELECT * from news_posts WHERE title LIKE '%$text%' OR post LIKE '%$text%' OR author LIKE '%$text%'"; $result = @mysql_query($query); if($result){ echo "<h1>found " . mysql_num_rows($result) . " results</h1><br />"; echo "<ul>"; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $mess=$row['post']; $view = 'page.php?id=' . $row['id']; echo '<li><a href="' . $view . '">' . $row['title'] . '</a></li>'; echo '<p style="margin-right:100px;margin-top: 0px;">'.snippet($mess, 200, true).'</p>'; } echo "</ul><br /> <a href=\"search.php\">Search Again?</a>"; } else { echo "No posts matched your query"; } } } else { ?> <form id="search" action="search.php?search" method="post"> Keyword: <input type="text" name="search" size="30" class="text" /><br /> <input type="submit" name="submit" value="Search" /> </form> <?php } ?>'; $language = 'php'; $path = 'geshi/'; // // Create a GeSHi object// $geshi = new GeSHi($source, $language, $path); // // And echo the result!// echo $geshi->parse_code(); ?> PHP: The error is about this line include_once("mysql_connect.php");
well you're not backslashing correctly, there's lots of other errors. remember, the source code is becoming a string assigned to a variable ($source = 'string of source code') so you have to make sure it's parsed correctly.
I put manually a backslash before every single quote and worked. Is there a function that does this, I mean that adds backslashes before every single quote?
Thank you for help szalinski, but there is another problem now. First time I had had just a html file with the code that I wanted to be printed to the screen with geshi. Now I put the content of that file in the database and when I printed to the screen, from database, I got a mess. I don't have colors anymore and the spaces are not anymore where they should be. What did the mysql to the file content that the geshi program doesn't work anymore?
Try putting the result from the database within <code></code> or <pre></pre> tags before parsing using Geshi?
I tried to put geshi code after I take the code from my data base <?php include_once 'geshi.php'; if ((isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { $id = $_GET['id']; } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { $id = $_POST['id']; } else { echo 'Please choose a news post to view.'; exit(); } $query = "SELECT title, post, author, DATE_FORMAT(date, '%M %d, %Y') as date FROM news_posts WHERE id='$id'"; $result = @mysql_query($query); if ($result) { $row = mysql_fetch_array($result, MYSQL_ASSOC); $mess = stripslashes($row['post']); $mess = stripslashes($mess); $mess = preg_replace("/rn/i"," ","$mess"); echo '<h2>'.$row['title'] . '</h2><p class="blog_text"> Posted by : <b>' . $row['author'] . '</b><br /> on ' . $row['date'] . '<br /><br />' . $mess . '<br /><hr /></p>'; $language = 'php'; $path = 'geshi/'; // // Create a GeSHi object// $geshi = new GeSHi($source, $language, $path); include("comments.php"); } ?> PHP: but still doesn't work. Any idea?