TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   help with code (http://www.talkphp.com/absolute-beginners/2182-help-code.html)

sarmenhb 02-04-2008 07:19 AM

help with code
 
im trying to use file() to grab the source code of a webpage and position the pointer to where the keywords are displayed and print them to the screen. but i keep getting errors, can you see why?

i thank thee from the deepest

Code:

<?php
if(isset($_POST['submit'])) {

$code = $_POST['url'];
$source = file($code);

foreach ($source as $line_num => $output) {
//for each key as value  key is hidden , value is line number looking in $source
   
        $str = $output;
        $start = strpos($str, 'content=\"') + 1;
        $end = strpos($str, "\"");
        $keyword = substr($str,$start,$end, - $start);
        $keys = explode(",", $keyword);
       
}
        for($i=0;$i<count($keys); $i++)
        { echo $keys[$i]."<br/>";
}

else {

?>
<html>
<head>
</head>
<body>
<form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
url: <input type="text" name="url"/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<? } ?>

Error: arse error: syntax error, unexpected T_ELSE in C:\wamp\www\test.php on line 21

sjaq 02-04-2008 08:51 AM

Try indenting your code next time, its easier on the eyes ;-)
PHP Code:

<?php
    
if(isset($_POST['submit'])) { 

        
$code $_POST['url'];
        
$source file($code);

        foreach (
$source as $line_num => $output) {
        
//for each key as value  key is hidden , value is line number looking in $source
    
            
$str $output;
            
$start strpos($str'content=\"') + 1;
            
$end strpos($str"\"");
            
$keyword substr($str,$start,$end, - $start);
            
$keys explode(","$keyword);
    
        }
        
        for(
$i=0;$i<count($keys); $i++) { 
            echo 
$keys[$i]."<br/>";
        }

    } else { 

?>
<html>
    <head>
        <title></title>
    </head>
    <body>
        <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
            url: <input type="text" name="url"/><br/>
            <input type="submit" name="submit" value="submit"/>
        </form>
    </body>
</html>
<? ?>

It looks like you forgot to close the for loop:
PHP Code:

for($i=0;$i<count($keys); $i++) 
    { echo 
$keys[$i]."<br/>"

b.t.w. I hope you know this script is really insecure at the moment, you're including a file that the user can specify without cleaning up the input, so someone could just put in /etc/passwd in the POST field and get that file. I always use str_replace to remove every / from the given string.


All times are GMT. The time now is 11:18 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0