Parse error: parse error, unexpected $end in C:\xampp\htdocs\keyword.php on line 36

Discussion in 'PHP' started by protocol96, Feb 15, 2007.

  1. #1
    Thanks in advance.

    My sincere apologies for the confusion

    <?php
    function highlight_search_keywords($text)
    {
    	$url="http://www.google.com/search?q=keyword&meta=";	
            @extract(@parse_url($url));
    	
    
            
            if (preg_match('/(google|msn|yahoo)/i', $host) AND preg_match('/[qp]=([^&]+)/i', $query, $keywords))
            {
                    $keywords = preg_split('/[\s\+\,]+/', rawurldecode($keywords[1]), -1, PREG_SPLIT_NO_EMPTY);
                    
                    foreach (array_unique($keywords) AS $keyword)
                    {		
    				
    
                            $text = preg_replace('/('. preg_quote($keyword) .')/i', '<span style="color: red; font-weight: bold;">$1</span>', $text);
    				
                    
    			}
            }
            
            return $text;
    }
    echo ("welcome home to the keyword");
    
    $page = $_SERVER['PHP_SELF'];
    	  $fp = fopen($page, "r")
    		or die("Could not contant $page");
    	while($new_text = fread($fp,100)){
    	$text =$new_text;	
    	}
    	fclose($fp);
    
    echo highlight_search_keywords($text);
    ?>
    PHP:

     
    protocol96, Feb 15, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    There's a double quote missing in this line.
    
    or die("Could not contant $page);
    
    PHP:
     
    nico_swd, Feb 15, 2007 IP
  3. protocol96

    protocol96 Peon

    Messages:
    413
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry Nico, i posted that and that thing just popped up, but now its given me different error.
     
    protocol96, Feb 15, 2007 IP
  4. 3l3ctr1c

    3l3ctr1c Peon

    Messages:
    380
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think you left "}" in the program.
     
    3l3ctr1c, Feb 15, 2007 IP
  5. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #5
    
    <?php
    # object buffers are your friend :)
    ob_start();
    function highlight_search_keywords($text)
    {
            $url="http://www.google.com/search?q=keyword&meta=";    
            @extract(@parse_url($url));
            if (preg_match('/(google|msn|yahoo)/i', $host) AND preg_match('/[qp]=([^&]+)/i', $query, $keywords))
            {
                $keywords = preg_split('/[\s\+\,]+/', rawurldecode($keywords[1]), -1, PREG_SPLIT_NO_EMPTY);
                foreach ( array_unique($keywords) AS $keyword )
                {        
                        $text = preg_replace('/('. preg_quote($keyword) .')/i', '<span style="color: red; font-weight: bold;">$1</span>', $text);
                }
            }
            return $text;
    }
    # ALL HTML CONTENT
    echo "welcome home to the keyword";
    
    
    # NO MORE HTML AFTER HERE
    $final_page = highlight_search_keywords( ob_get_contents() );
    # clean the object buffer
    ob_end_clean();
    # echo the page with function executed on ....
    echo $final_page;
    ?>
    
    PHP:
    http://php-learner.com/p.php

    Fixed :)
     
    krakjoe, Feb 15, 2007 IP