PHP - Copying Entries Not Found In File.
I'm trying to compare 2 files, each with data separated by ::. I'm trying to make a comparison that if the data to the left of the separator from one file is not found in the same column of the other file, then it is copied to an array.
For example: file1.txt abc::def ggg::hhh mmm::ppp file2.txt abc::def zzz::aaa bbb::ccc So... ggg::hhh mmm::ppp is copied from file1.txt because ggg and mmm was not found on the same side in file2.txt ...but I'm not getting any error message with this. The operation just hangs. Code: [Select] <?php $dic1 = file('file1.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $dic2 = file('file2.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $titleText = array(); // Storing results into this array. foreach ($dic1 as $dic1line){ list($dic1field1, $dic1field2) = explode('::', $dic1line); foreach ($dic2 as $dic2line){ list($dic2field1, $dic2field2) = explode('::', $dic2line); if ($dic1field1 != $dic2field1) { // Found a non match in DB. array_push($titleText, "$dic1field1 :: $dic1field2\n"); // Store all finds in array. } } } // Finish outputting anything left over. if (empty($titleText)) { // $value was not found -- array is empty. echo 'All matched, or something else.'; } else { $arrayOut = implode("", $titleText); // output the results found in the search. echo $arrayOut; } unset($value); ?> Anyone know how to do this? Thanks. Similar Tutorialshttp://bayarearcsociety.com/prototype/index.php When I click the Home link in the nav panel I get these errors Code: [Select] Warning: include(/content/pages/testpage.php) [function.include]: failed to open stream: No such file or directory in /home/bayare27/public_html/prototype/content/maincontent.php on line 7 Warning: include() [function.include]: Failed opening '/content/pages/testpage.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php:/home/bayare27/php') in /home/bayare27 /public_html/prototype/content/maincontent.php on line 7 index.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" > <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-language" content="en" /> <link type="text/css" rel="stylesheet" href="css/reset.css" /> <link type="text/css" rel="stylesheet" href="css/960.css" /> <link type="text/css" rel="stylesheet" href="css/custom.css" /> <title></title> </head> <body> <div id="wrapper" class="container_12"> <div id="header" class="grid_12"> <div id="left-header" class="grid_5 alpha"></div> <div id="newsflash" class="grid_7 omega"><?php include('content/newsflash.php'); ?></div> </div> <div id="leftmenu" class="grid_3"><?php include('content/menu.php'); ?></div> <div id="maincontent" class="grid_9"><?php include('content/maincontent.php'); ?></div> <div id ="footer" class="grid_12"><?php include('content/footer.php'); ?></div> </div><!-- end wrapper --> </body> </html> menu.php <?php ?> <div class="content"> <ul id="menu"> <li><a href="<?php echo htmlentities($_SERVER['SCRIPT_NAME']); ?>?page=testpage"><span>Home</span></a></li> <!-- Tried both these $_SERVER['PHP_SELF'] and $_SERVER['SCRIPT_NAME']--> <li><a href=""><span>About us</span></a></li> <li><a href=""><span>Schedule</span></a></li> <li><a href=""><span>Media</span></a></li> <li><a href=""><span>Products</span></a></li> <li><a href=""><span>Miscellaneous</span></a></li> </ul> </div> testpage.php <?php ?> <p> lalalaa </p> The file structure on the server is: prototype content - I know these are ok pages - testpage.php is in this file css - I know these are ok images - I know this one is ok Just don't know what to do next. Thanks I apologize, I thought I was posting in php. I assume you will move it. Hello, I'm requesting your help here cause I'm really confused. I'm looking for deleting entries when an image doesn't load on my links test. I got all my links in a .txt file like this : links.txt = Code: [Select] <div class="gallery"> <a href="http://www.website.com/page"> <img src="http://tc16.easythumbhost.com/image.jpg" onerror="ImgError(this)"/> </a> </div> #enddiv the "onerror" code in img src sends an "Image Missing" pic. What I'd want is to change the "onerror" function to open a php script which deletes all the lines of the div. This is the script I use to show the links on my page : Code: [Select] $links = "links.txt"; $fd = fopen ($links, "r"); $content = fread ($fd,filesize ($links)); fclose ($fd); $delimiter = "#enddiv"; $splitcontent = explode($delimiter, $content); $output = array_slice($splitcontent, 0,100); foreach ( $output as $divs ) { echo "$divs"; } I've searched hours and tried lots of codes before posting Help would be very appreciated. Thanks. Hi Hope someone can help me please. I have constructed an audio dictionary and have discovered an error now that I have added a few entries to the database. A user can search the database and can click on a result to be taken to the content associated with the entry he chooses. This is the search function; Code: [Select] $search=$_POST["search"]; //get the mysql and store them in $result $result = mysql_query("SELECT word FROM pro_words WHERE word LIKE '%$search%'"); //get the db content that is specified above if (mysql_num_rows($result) < 1) { echo "<br><br><h2> We didn't find anything. Sorry - we did look though.</h2>"; }else { echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr><td align="left"><b>Word</b></td></tr>'; echo "<br><br><h2>Success! Here's what we found:</h2><br>"; while ($r=mysql_fetch_array($result, MYSQLI_ASSOC)) echo '<h2><tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td></tr></h2>'; } You will see that content is displayed in a new file called word.php. This is relevant code from word.php Code: [Select] $query = "SELECT word,word_type1,sentence1,word_type2,sentence2,word_type3,sentence3 FROM pro_words"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<div class="colmask rightmenu">'; echo '<div class="colleft">'; echo '<div class="col1">'; echo '<p>Here are some example sentences that show how we use the word; </p>'; echo '<div id="small"><i> ' . $row['word_type1'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence1'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type2'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence2'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type3'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence3'] . '</p></div>'; } The problem is that every entry on the database is echoed in word.php whereas I would like only the entries for the word selected to appear. Thanks in advance for any help; do say if you need more info. I have a Windows-style ini file that contains entries as such:
[Timers] Timer(1)=50 Timer(2)=30 Timer(3)=20 The entries represent an array of 3 different timers Apparently parse_ini_file can't deal with the () format. Is there any way to use this format ini file without having to change how arrays are designated? //if any items in order table then display all items in order table $order_sql = "select * from orders"; $order_result = $handle -> query( $order_sql ); if($order_result->num_rows) { echo '<table bgcolor=#FFFF66 ><td>'; while ($order = $order_result -> fetch_assoc()) { $category_sql = "select category from category where category_id = {$order['category_id']}"; $category_result = $handle -> query( $category_sql ); $category_name = $category_result -> fetch_row(); $menu_sql = "select item_name from menu where item_id = {$order['item_id']}"; $menu_result = $handle -> query( $menu_sql ); $menu_name = $menu_result -> fetch_row(); echo $category_name[0] . ': ' . $menu_name[0] . ' ' . $order['size'] . ' ' . $order['type'] . ' ' . $order['amount'] . '<br />'; //insert data into order.txt file for print $file_insert = $category_name[0] . ": " . $menu_name[0] . " " . $order['size'] . " " . $order['type'] . " " . $order['amount'] . "\r\n"; @ $fp = fopen( 'order.txt', 'ab' ); if($fp) { fwrite( $fp, $file_insert, strlen( $file_insert ) ); } else { echo 'could not insert data into order.txt file for print, CLICK ON NEW ORDER'; } fclose($fp); } This is probably an easy one, but I can't figure it out and it's pretty much not searchable. on a linux-machine i have installed filezilla the filezilla runs pretty well and all is ok. now i need to have the passwd that i have stored years ago. The passprhase is stored in a plain in a file called sitemanager.xmlfile I want to find that file and open it with a terminal command. find . -name *.sitemanagerwell i thought that this will return the file I'm looking for. Now how do I open it automatically, without typing the name? find . -name *sitemanager.xm | openThis doesn't work. It says it doesn't found the open command. question: why it does not work on opensuse? should i use any other command - eg the following: find . -name *xyz | xargs openor find . -name *sitemanager.xml | xargs openor find . -name *.xyz -exec open {} \;and find . -name *.xyz -exec open {} \; .any and all help will be greatly appreciate again: what is wanted and needet is to find out the passphrase in the filezilla-configuration I want to copy everything in templates/blue to the folder code/ However: shell_exec("cp -r 'templates/blue' 'code'"); Creates a folder called blue inside code. I tried cp -r 'templates/blue/*' 'code', but that didn't do anything. Any ideas? Hi all, Maybe someone can help me with this, I am looking to copy specific content from one website to another automatically. So when ever one website updates the certain content the other site is automatically updated with it to. I have tried using file_get_contents but this wasnt working. Does anyone have any ideas? Im looking to copy https://annablais.scentsy.us/Home starting at line 270, the end is determined by how many Parties there are. Thanks all Ok fellas....this one has me stumped. I am trying to copy a whole bunch of pictures from one directory into a new directory. However, the new directory will store the images based upon the user's id. Initially I stored all the images in one directory. HUGE mistake.. That single directory is over 5GB and takes and eternity to open and edit the files for 1 single user. So I need to separate them out. Anyways, here is what I am trying to do in theory. All the information about the user and the file they uploaded is stored in my database. But how do I create a script that is somewhat dynamic? One that will refresh the copy file script for each result. Here is the general idea....or a conversation starter code i am working with so far. Code: [Select] <?php include 'db_connect.php'; $userId=2; // Make the directory that will store the users images with the desired folder structure $structure = './images/' .$userId. ''; // create the directory and set permissions if (!mkdir($structure, 0777, true)) { die('Failed to create folder'); chmod($structure, 0777); } //Query the database for the images $query_image = "SELECT * FROM images WHERE angler=$userId ORDER BY submit_id DESC"; $image_result = mysql_query($query_image) or die(mysql_error()); // get count of how many rows in case we need that info $rowCount = mysql_num_rows($image_result); //get the results into an array by setting each result as a variable while($row = mysql_fetch_assoc($image_result)) $galleryresults[]= $row; //now move files $file = './submitted_pics/{$galleryresults[0]['image']}'; $newfile = './images/' .$userId. '/{$galleryresults[0]['image']}'; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } ?> Ok, I would just like some advice on how to go about doing something. A website that alot of my friends use to make their builds in-game goes down frequently causing them not to be able to pull up their build information. I would like to be able to use php to copy not only the html source, but the images as well to my websvr to be able to view when their site is offline. Now I know I could simply just click page -> save as complete html in internet explorer and then upload that... However I don't want to have to do that for everyone stuff.. its time consuming.. I was hoping to automate the process with a script. I know how to get the html source from a website, but I don't know how to pull the content "pictures ect." to make it actually look like their site and have more than just text. I'll appreciate any advice you can give, I think some simple direction should be enough to get me going. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313840.0 I'm using copy() to copy an image to a different directory. The problem is the image could be in 1 of 3 folders. With out knowing which folder its in how can I do this? I'm trying to allow a user to upload an image, and have that image copied to an Image folder on the server When I run the code I get the success message near the bottom of the code, but the image never gets copied to the folder. I'm not sure what's causing it to not copy the image if($_POST["store"] != "") // if upload was hit { $fileExt = strrchr($_FILES['userfile']['name'], "."); // grab extension if($fileExt != ".jpg" && $fileExt != ".jpeg") // check extension { $_SESSION["badFileType"] = "You cannot upload a file of type ".$fileExt; // set error } else { $fileName = $_FILES['userfile']['name']; // set file name if(!is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "Problem: possible file upload attack!"; // set error exit(); // end } $upfile = "../Images/lg_".$category.$counter.".jpg"; // set path $newFileName = $category.$counter.".jpg"; // set new file name if(!copy($_FILES['userfile']['tmp_name'], $upfile)) // if not able to copy { echo "Problem: file could not be copied to directory!"; // set error exit(); // end } $_SESSION["badfileType"] = "File uploaded successfully!"; // set success message } } else { $_SESSION["badFileType"] = ""; // clear error } I've been developing a php application that runs my entire company for the last 4 years. One of the things I never thought of until now is that the server guys or anyone else could copy the source code and db and be able to start up another company which brings up my question to you.... How would you protect your application? My thought is to create one small php file that is encrypted with something that is required to make the entire site run (not sure at this point what it would be that they couldn't just rebuild). Then if this file sees it's on a different domain/ip it requests data from my site which logs the info for me to look at. If I find out it's something not approved, it would then not allow the program to run and will give a error. What is your idea? Below is the part of my code that creates the html table. How do I add pagination every 30 entries? $db = mysql_connect("localhost","trend_learnu","asdfasdf"); mysql_select_db("trend_learningdb",$db); $result = mysql_query("SELECT * FROM Peoples ORDER BY number ASC"); $table = '<table width="608" border="0" align="center" cellpadding="10" cellspacing="0"> <tr> <td style="color:#fff;" width="207" bgcolor="#425d74"><strong>Firstname</strong></td> <td style="color:#fff;" width="204" bgcolor="#425d74"><strong>Lastname</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Date</strong></td> <td style="color:#fff;" width="197" bgcolor="#425d74"><strong>Weight</strong></td> </tr>'; while($row=mysql_fetch_array($result)) { $firstname = $row['Firstname']; $lastname = $row['Lastname']; $weight = $row['Weight']; $date = $row['Date']; $table.= '<tr>'; $table.= '<td bgcolor="#e8f4ff">'.$firstname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$lastname.'</td>'; $table.= '<td bgcolor="#e8f4ff">'.$date.'</td>'; $table.= '<td bgcolor="#e0ffe6"><strong>'.$weight.'</strong></td>'; $table.= '</tr>'; } $table .= '</table>'; echo $table; mysql_close($con) the problem is that when I add an item to be displayed in the blog, shows three instead, which two are empty. It should not create three entries when I just add one entry. How can I fix this? <?PHP /* define the blog content file name */ $filename = "myBlogContent.txt"; ?> <?php /* check to see if the file exists */ if (!file_exists($filename)) { echo "The Blog Is Empty"; }else{ /* get the file lines into an array */ $BlogArray = file($filename); /* count the number of blog entries */ $count = count($BlogArray); $i=0; while($i<$count) { $new_array = explode("|", $BlogArray[$i]); echo "Posted by: " . $new_array[1] . "<br>"; echo "Posted on: " . date("m/d/y h:iA", time($new_array[0])) . "<br>" echo "Title: " . $new_array[2] . "<br>"; echo $new_array[3] . "<hr>"; $i ++; } } ?> <?PHP /* obtain the form data */ $who = $_POST['who']; $title = $_POST['title']; $content = $_POST['content']; $content = str_replace(array("\r\n", "\r", "\n"), "<br>", $content); /* create timestamp variable for current date and time */ $when_ts = time(); /* define the blog content file name */ $filename = "myBlogContent.txt"; /* prepare the variables for adding to the file */ $new_line_content = $when_ts . "|" . $who . "|" . $title . "|" . $content . "\n"; /* open the file in the APPEND MODE */ $fh = fopen($filename, 'a+') or die("can't open file"); /* add the new content */ fwrite($fh, $new_line_content); /* close the file */ fclose($fh); //exit; // Closes further script execution . ?> I am making login system using codeigniter. When I run my code i get this error. Code: [Select] The requested URL /ci_login/user/login was not found on this server. here is my code so far user.php file which is in controller folder Code: [Select] <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class User extends CI_Controller { function __construct() { parent::__construct(); } function index() { } function login() { if($this->form_validation->run() == FALSE) { $this->load->view('view_login'); } else { echo "Successfull"; } } } view_login.php file which is in view folder Code: [Select] <html> <head> <title>Login</title> </head> <body> <h1>Please Login!</h1> <p>Use the login form below to login.</p> <div id="login_form"> <?php echo form_open(base_url(). 'user/login' ) ?> <label>Username:</label> <div> <?php echo form_input(array('id' => 'username', 'name' => 'username')); ?> </div> <label>Password:</label> <div> <?php echo form_password(array('id' => 'password', 'name' => 'password')); ?> </div> <div> <?php echo form_submit(array('name' => 'submit'),'Login'); ?> </div> <?php echo form_close(); ?> </div> </body> </html> help please how can I solve this error? Hi guys Im trying to delete multiple images from a page with the code below, I have retirieved the images successfully but i can not delete the with checkbox, wht it does is just refereshing the page and thats it, what im trying to do is to delete the image from the database but it wont. can u help me please? <?php session_start(); include ("../../global.php"); //welcome messaage $username=$_SESSION['username']; echo "$username"; $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_assoc($query)) { $user_id = $row['id']; } $ref=$_GET['reference']; $images=mysql_query("SELECT * FROM img WHERE refimage='$ref'"); while($row = mysql_fetch_array($images)) { $image=$row['image']; $thumb=$row['thumb']; ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="" method="post" action=''> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo "<a href='$image' rel='lightbox[roadtrip]'><img src= '$thumb' width='60' height='40' alt='$title'>";?></td> <? } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this $delete = $_REQUEST['delete']; if( $delete != '' ){ $checkbox = $_REQUEST['checkbox']; $count = count($_REQUEST['checkbox']); for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $del = mysql_query("DELETE FROM img WHERE id = '$del_id'"); } } ?> Hello... I have a .txt database with ~100 records. I only want to show the 15 records that are at the top (referring to reading order of the file). Here is my php code to display the records. http://www.flcbranson.org/mobile.php?content=mobile-freedownloads.php if you want to see the results of the code, below. Code: [Select] <?php $index_file = 'services/series/Index-Date.txt'; $fd = fopen($index_file, 'r'); if ($fd) { while (!feof ($fd)) { $seriestitle = trim(fgets($fd, 1024)); // Series Title if(feof ($fd)) break; $seriessubtitle = trim(fgets($fd, 1024)); // Series subtitle $seriesinfo = trim(fgets($fd, 1024)); // Series Info (Church name) $serieslocation = trim(fgets($fd, 1024)); // City, State $seriesindex = trim(fgets($fd, 1024)); // Series index file $seriesstatus = trim(fgets($fd, 1024)); //Online Only? $divider = trim(fgets($fd, 1024)); // Divider $seriestitle2 = $seriestitle; $seriestitle3 = str_replace("'", "%27", $seriestitle); // Kind of makes the alt= below work "God's Will" ends up being "God%27s Will" but without is "God" if(strstr($seriestitle,"<")) { $seriestitle2 = strip_tags($seriestitle); } $seriestitle2 = urlencode($seriestitle2); if(file_exists("images/ProductCovers/".substr($seriesindex,0,-4).".jpg")) { echo "<img src='images/ProductCovers/".substr($seriesindex,0,-4).".jpg' width='115' height='150' border='0' alt='".substr($seriestitle3,7)."'><br />"; } } fclose ($fd); } ?> I'm assuming that "for" would do the trick, but when I tried I got 10 copies of every record. Hehehe... I'm guessing that it's a quick fix. Thanks... JJ Hello, For starters I'm not sure if what I want to do is possible, but if it is I would like your input. I have a script that will show a number of fields to fill out in a second form based on the number the user puts into the first from. the problem is that only the last one saves into the database and not all of them. Code: [Select] <form auction="index.php" method="post"> System Name: <input type="text" name="systemname"> Number of E-sites: <input type="text" name="events"> Number of Sigs: <input type="text" name="sigs"><br> <input type="reset" name="reset" value="Reset"> <input type="submit" name="start" value="Start"> </form> <form auction="index.php" method="post"> <?php $events = $_POST['events']; $system = $POST['systemname']; if (isset($_POST['start'])) { $num = $_POST['sigs']; $i = 0; While ($i < $num) { echo "Sig ID: <input type=text name=sigid>"; echo "Type: <input type=text name=type>"; echo "Name: <input type=text name=name>"; echo "Notes: <input type=text name=notes>"; echo "<br>"; $i++; } } ?> <input type="submit" name="enter" value="Enter"> </form> <?php $sigid = $_POST['sigid']; $type = $_POST['type']; $name = $_POST['name']; $notes = $_POST['notes']; mysql_connect('xt', 'x', 'x'); mysql_select_db('wormhole'); if (isset($_POST['enter'])) { $query = "INSERT INTO sites VALUES ('$system','$events','$sigid','$type','$name','$notes')"; mysql_query($query); } ?> How do I get it so all the data saves, lets say that $num = 5, I want all 5 to save not just the last one. |