scanning and replacing<

liunx

Guest
i know how to pen a php file, read it, write to it, etc.... but heres my question:

how do i scan through the file to find a certain word, say "$wow", and change the contents of the variable "$wow"?Kind of a weird thing to do.. Just insert $wow = 'new content'; somewhere... Since the value can change many times throughout the script, this could become a very complicated thing to accomplish.. If you're using it more like a constant, and have a line that looks something like this:
$wow = 'content';
Then you can search and replace it using the PCRE functions. Could you possibly elaborate your problem a bit more?okay, i have this script (<!-- m --><a class="postlink" href="http://24.238.145.68/public/morrowasted/v9/skate/kee2.php">http://24.238.145.68/public/morrowasted ... e/kee2.php</a><!-- m -->) that uses the following code:

<?

$img = array();
$dir = "smilies";
$perPage = 50;
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if( $file != "." && $file != "..") {
$img[] = $file;
}
//echo "<img src=http://www.htmlforums.com/archive/index.php/\"smilies/$file\">";
}
closedir($dh);
}
}
if($dir != TRUE){
echo "error reading dir";
}



$page = isset($_GET['p'])?$_GET['p']:1; //checks to see if the page variable is set
if( $page < 1 ) { //checks if page is less than 1
$page = 1;
} else if ( $page > ceil(sizeof($img)/$perPage) ) { //checks if page is too high
$page = ceil(sizeof($img)/$perPage);
}
for( $num = (($page-1)*$perPage); $num < (($page-1)*$perPage+$perPage); $num++ ) {

if( $img[$num] !== null ) {
echo "<img src=http://www.htmlforums.com/archive/index.php/\"$dir/". $img[$num] ."\">";
}
}

echo "<center>";
echo "Currently Displaying 50 smileys per page";
ECHO "<BR />";
echo "<a href=http://www.htmlforums.com/archive/index.php/\"?p=". ($page+1) ."\">Next Page</a>";
echo "</center>";
?>

i want to be able to open this file from another file and change the values of $img, $dir, and $perPageI would make those variables be set by the query string, it makes things a lot more dynamic. Why the need to change the actual source code? That seems like a very bad programming practice to pursue...load that file into a textarea and then edit the text you want and resave it.

like a big notepad for the internet.Well I presumed it would be some kind of automated process. If not, he might as well use the real notepad?
 
Back
Top