Jas wrote:
Anyone have a good method of grabbing the current page and reading data
from it?
For example:
<?PHP
// find all form fields for current page
function FindFormFields( $page ) {
if( empty( $page ) ) {
$data = -1;
} else {
if( ( $fh = @fopen( $page, "r" ) ) === FALSE ) {
$data = -1;
} else {
while( !feof( $fh ) ) {
$line = fgets( $fh, 512 );
if( eregi( "<input type=\"", $line ) ) {
$data[] = $line;
}
}
fclose( $fh );
}
}
return $data;
}
echo FindFormFields( "http://php.net" );
?>
The above code would output the following:
Array
(
[0] => <input type="text" name="pattern" value="" size="30"
accesskey="s" />
[1] => <input type="image"
)
Now for the problem I am having and a description of what I am trying to
accomplish:
I want to dynamically generate a form and in doing so I would like to
dynamically generate the following javascript features for said page
- javascript form validation
- javascript form field focus
The problem is if I call the current page that is being generated such as
<?PHP
echo FindFormFields( "http://" . $_SERVER['SERVER_NAME'] .
$_SERVER['REQUEST_URI'] );
?>
Not only does it take a helluva long time to load the page but it also
creates a nested array with duplicate values.
I'm not surprised it's taking a while to load in your browser. I think
you have a serious nested loop issue there. What you're doing is telling
the PHP engine to load the same page again. When it does that it's going
to call your function *again* on the same page. Rinse and repeat.
But i don't understand what putting those tags in an array is going to
accomplish. Perhaps there's a lot more to this, but i'd be inclined to
set up my validation in a more targetted manner.
brian
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php