PHP - Search With String In Url
Hello,
Im trying to have my search on my site so the URL goes to index.php?page=search&string=WhatEverWasTyped How is this possible? Similar TutorialsAlright, so I have a textarea where users can put in text. Everytime they put [ani] and click submit, I want the output to change [ani] into an html code: <img src="mypic.gif"> Is this possible? Hey all, I'm using the form 'method="get" action="results.php"' on my search form... Say someone uses my 'Photo search' to search my database for aircraft, and leaves all fields blank. In this case, the only field of the search is 'aircraft'. This will take the user to 'results.php?aircraft='. Is there anyway to remove the sting if there is no search value? So it would just read 'results.php'? This is the code i have so far: Code: [Select] <?php if(isset($_GET['aircraft'])){ $aircraft = $_GET['aircraft']; } if($aircraft==""){ $aircraft = mysql_query("IGNORE aircraft"); } ?> Thanks in advanced! Hi, I am trying to search a string for a string of characters in this order ../ and carry out relevant if statements but it returns the same result every time. On echoing my $pos, $pos2, $pos3 and $pos4 variables the first two come back 0 and they are the strings that do contain ../ but the if statements perform the same? I don't understand, any ideas? Thanks... Code: [Select] <?php $logo = $info ['logo']; $pos = strpos($logo, "../");//check if image contains ../ if ($pos == 0) {} else { $logo = substr($logo, 3);} $image1 = $info ['image1']; $pos1 = strpos($image1, "../");//check if image contains ../ if ($pos1 == 0) {} else { $image1 = substr($image1, 3);} $image2 = $info ['image2']; $pos2 = strpos($image2, "../");//check if image contains ../ if ($pos2 == 0) {} else { $image2 = substr($image2, 3);} $image3 = $info ['image3']; $pos3 = strpos($image3, "../"); //check if image contains ../ if ($pos3 == 0) {} else { $image3 = substr($image3, 3);} ?> Hey all, I have a quick question and I know the answer is probably pretty easy but i've been working on it a while now and can't figure out how to get this done. SOO the situation is. I am looping through an RSS feed and with each entry I want to search for a brand name within the title, and add a company logo beside the entry. I was playing with something like this but it doesn't work real well.. // Find Kokatat $find = "Kokatat"; if(strstr($string, $find)) { $icon = "koksm.jpg"; } else { $icon = ""; } I appreciate any input! Hello I am facing a problem which i can not handle. I appreciate for any help. My Database is: Code: [Select] CREATE TABLE IF NOT EXISTS `shops` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `options` text, `user_name` varchar(250) NOT NULL , PRIMARY KEY (`id`), UNIQUE KEY `user_name` (`user_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='user data stored' AUTO_INCREMENT=1 ; And some sample data as below: Code: [Select] INSERT INTO `users` (`id`, `options`, `user_name`) VALUES (1, 'apple-orange-grape-bmw-toyota-fig-', 'user1'), (4, 'apple-tomato-pc-notebook-yellow-', 'user2'), (5, 'blue-green-orange-cdrom-', 'user3'), (6, 'orange-yellow-blue-pink-bread-', 'user4'); How can i display how many apples or green or any item selected by user? So far i tried in_array, array_count_values but seems no one is working. Regards Somewhat new with PHP but I think I'm on the right track. I'm trying to search for a serial number on a sql table. I want a response of the serial # and what column its in. There is 4 columns if that helps (id, 30, 32, 31). (serials 002062008002220 002062008002222 002062008002233 are in the table)
When I enter in a serial # 002062008002220 (all serials are 16 digits long). I get a blank page to show up...
my form
<form action="search.php" method="get"> <input id="serials" type="text" name="serials" /> <input type="submit" /> </form>my php <?php $con=mysqli_connect("localhost", "xxx", "xxx", "nsmserials"); if (mysqli_connect_errno ()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $search = mysql_real_escape_string($_REQUEST['serials']); $query = "SELECT 30, 32, 31 FROM nsmtable WHERE 30 LIKE '%$search%' OR 32 LIKE '%$search%' OR 31 LIKE '%$search%'"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)){ echo "<li><span class='name'><b>{$row['serials']}</b></span></li>"; } mysqli_close($con); ?> Hello, Okay for some reason i cannot do this, when i open a file in php and search for string, it doesn't seem to work, some codes i tried: Code: [Select] $filename = 'example.txt'; $searchfor = 'hello'; $fh = fopen($filename, 'r'); $olddata = fread($fh, filesize($filename)); if(strpos($olddata, $searchfor)) { //fount it } else { //can't find it } fclose($fh); (above it just sample text, i was hoping you could give me sample code that will work) I tried many others like strstr, stristr, preg_replace etc etc, doesn't seem to find it.. this is my text file: Code: [Select] sdfsdfsdfsdfsdf[b]hello[/b]sdvsdf dfadfsdfsdfsddfsdf sdfsdfsdfs sdffffffffffffffffffffdv vsvdsdsf I don't want to find it by line, i want to simply open the text file and find the string.. thanks.. I am new to PHP and I am trying to write code which will perform a string search function based off of user specified directory + log file (ex: /home/log.txt) , and user specified string(s) to search for, the user can enter more than one string separated by '|'. Is egrep the correct way to go in terms of taking input separated by '|' Does/can php reconize quotations beyond the simple example I have below: $quote = "\""; if(strstr($test, $quote)){ echo "quote found"; } I'd like to detect any instance of a quote. Should I be including html such as " and/or other html quote symbols? Or does the simple example I have above suffice? Hi there
I have started using php excell and getting most of it right. But i am struggling to search active sheet and return what cell the string is in. below is my code.
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); set_time_limit(0); $directory = "/var/www/html/csvex/xls/"; $formatdirectory = "/var/www/html/csvex/toformat/"; $finishedformatdirectory = "/var/www/html/csvex/formatted/"; $savanadirectory = "/var/www/html/iretire/files/upload/1/"; $main = "/var/www/html/csvex/"; $files = scandir($directory, SCANDIR_SORT_DESCENDING); $newest_file = $files[0]; echo $newest_file; echo "<br>"; $oldfile = $directory.$newest_file; $newfile = $formatdirectory.$newest_file; $changedfile = $finishedformatdirectory.$newest_file; $crmfile = $savanadirectory.$newest_file; echo $oldfile; echo "<br>"; echo $newfile; echo "<br>"; if( !rename($oldfile, $newfile) ) { echo "File can't be moved!"; } else { echo "File has been moved!"; } //format the file date_default_timezone_set('Europe/London'); set_include_path(get_include_path() . PATH_SEPARATOR . './Classes/'); include 'PHPExcel/IOFactory.php'; $fileType = 'Excel5'; $fileName = $newfile; // Read the file $objReader = PHPExcel_IOFactory::createReader($fileType); $objPHPExcel = $objReader->load($fileName); //change font $objPHPExcel->getActiveSheet()->getStyle('a1:a6')->applyFromArray( $styleArray = array( 'font' => array( 'bold' => true ) ) ); $objPHPExcel->getActiveSheet()->getStyle('a6:aa6')->applyFromArray( $styleArray = array( 'font' => array( 'bold' => true ) ) ); $objPHPExcel->getActiveSheet()->getStyle('n16:aa16')->applyFromArray( $styleArray = array( 'font' => array( 'bold' => true ) ) ); //get INACTIVE MEMBERS $foundInCells = array(); $searchValue = 'INACTIVE MEMBERS'; foreach ($objPHPExcel->getActiveSheet() as $worksheet) { $ws = $worksheet->getTitle(); foreach ($worksheet->getRowIterator() as $row) { $cellIterator = $row->getCellIterator(); $cellIterator->setIterateOnlyExistingCells(true); foreach ($cellIterator as $cell) { if ($cell->getValue() == $searchValue) { $foundInCells[] = $ws . '!' . $cell->getCoordinate(); } } } } echo "<br>"; echo "<br>"; echo "this is where - - "; var_dump($foundInCells); echo "<br>"; echo "<br>"; // $objPHPExcel->getActiveSheet()->getStyle('a20')->applyFromArray( $styleArray = array( 'font' => array( 'bold' => true ) ) ); its located at //Get inactive members. another one i am struggling with is to see if file exists if not then do nothing if it does run the code. Hello, I am EXTREMELY new to PHP, and coding in general. I have attempted to search for an answer to this already, but I'm not sure I'm using terminology that will lead me to an solution, as I haven't come up with much. I'm hoping that someone can provide some assistance, or at least point me in the right direction for some reading. What I am trying to do it search a string for a match to any of 12 words. I'm wondering if there is a smarter way to do this than coding 12 different lines, each one looking for a specific word. If you can point me in the right direction, then thank you very much =) Currently I am using a script that displays the entire directory. However I am trying to use preg_match to try and figure out
how to just link to one file from the directory via a search string from a form.
I am probably not even close so please bare with me
<?php if (isset($_POST['filelook'])) { $filez = $_POST['filelook']; } /* edit $path to the directory you want to use edit $file_types to change the file types to show */ function file_type($file) { $searchString = $filez; $path_chunks = explode("/", $file); $thefile = $path_chunks[count($path_chunks) - 1]; $dotpos = strrpos($thefile, "."); return strtolower(substr($thefile, $dotpos + 1)); } $file_count = 0; $path = "./WinFiles/files"; $file_types = array('png', 'jpg'); $p = opendir($path); while (false !== ($filelook = readdir($p))) { $files[] = $filelook; } sort($files); echo "<b> Your file results:</b><br> "; if (file_exists($filez) && is_readable($filez) && preg_match($filez)) { echo '<a href="download.php?f='.$filez.'">'.$filez.'</a> <br/>'; //find filename like name searched for... if($file_count == 0) { echo "<b>No file match your file types</b>"; } } ?> Hi all, first time here as I am a bit stuck. I am by no means a programmer and I was hoping that someone out there may have a simple solution to my problem?... So here goes" I have a voucher/offers site up-and-running. The site content is generated from an external feed. I want to create other sites and I want to track what sales/clicks have come from where. An example of the feed: (http://www.awin1.com/awclick.php?mid=251&id=28971&clickref=[URL_REFERENCE]&p=http://www.247electrical.co.uk) As you will see, I have [URL_REFERENCE] in each link. I want to automatically change that part of the string in the database. Does anyone have any thoughts? I have a kind of search and react on my site. The user can search for a number in a column as below $search = mysqli_real_escape_string($link, $_POST["query"]); $query = "SELECT * FROM $table[$i] WHERE oemnr LIKE '".$search."%' ORDER BY model";
The code works fine but I want to expand the function to get match for other numbers also. The oemnr column today can be 12345 which shows up if the user type 12.... I want to expand the oemnr column as 12345/03124/34713, numbers separated with / or another character. If the user type 03... or 34... I want to find and show 12345 because it is on the same row and corresponds to the numbers on the same row. Is it possible to do in mysql? In php that kind of operation can be done with the explode function but I don't know how to use with mysql. Edited February 14 by jiggaI have some data in a table and some of it is Artist names stored as "Last, First" I need to be able to have the script search weather or not someone types "last, first" or "first last". Any ideas? Here's my code: <html> <head> <title>search script</title> </head> <body> <form name="form" action="search.php" method="get"> <input type="text" name="q" /> <input type="submit" name="Submit" value="Search" /> </form> <?php // Get the search variable from URL $var = @$_GET['q'] ; $trimmed = trim($var); //trim whitespace from the stored variable // rows to return $limit=100; // check for an empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; exit; } // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database ** EDIT REQUIRED HERE ** mysql_connect("localhost","username","password"); //(host, username, password) //specify database mysql_select_db("mydb") or die("Unable to select database"); //select which database we're using // Build SQL Query $query = "select * from songs where Title like \"%$trimmed%\" or Artist like \"%$trimmed%\" order by Title"; // EDIT HERE and specify your table and field names for the SQL query $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); // If we have no results, offer a google search as an alternative if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; $count = 1 + $s ; // now you can display the results returned echo "<table border=1>"; while ($row= mysql_fetch_array($result)) { $title = $row["Title"]; $artist = $row["Artist"]; $number = $row["Number"]; echo "<tr><td>$count.)</td><td>$title</td><td>$artist</td><td>$number</td></tr>" ; $count++ ; } echo "</table>"; $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 10</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; echo " <a href=\"$PHP_SELF?s=$news&q=$var\">Next 20 >></a>"; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<p>Showing results $b to $a of $numrows</p>"; ?> </body> </html> The situation is that I have a large string with some identifiers to say "replace me" with something else. My goal is to replace the values, but if one replacement includes one of the other keys, I don't want to replace it.
For example:
<?php $str = 'some blob ~abc~ followed by ~def~'; $arr_orig = array( '~abc~', '~def~' ); $arr_new = array( 'value~def~', 'blah' ); echo str_replace( $arr_orig, $arr_new, $str ); ?>This will echo: some blob valueblah followed by blah But that's not what I'm trying to accomplish. Basically, I want ~abc~ to be replaced with the literal: value~def~ and for the ~def~ that happens to be part of that string to NOT be replaced. I hope what I'm asking is clear. Basically, preg_replace/str_replace with arrays seems no different than just doing a FOR loop and replacing ~abc~ and then ~def~. But that's not what I need. I'm hoping that if ~abc~ is replaced with text that happens to be another identifier -- ~def~, ~xyz~, whatever -- that this already replaced text is not again replaced. Is there a built-in function to do something like this? If not, should I just parse the whole string and count characters or something? Seems like a pain (and slow!) The result pages is supposed to have pagination like google help me please
Hi, I am trying to make some adjustments to uploadify.php which comes with the latest version of uploadify (3.0 beta), so that it works with a session variable that stores the login username and adds it to the path for uploads. Here is uploadify.php as it currently looks: Code: [Select] <?php session_name("MyLogin"); session_start(); $targetFolder = '/songs/' . $_SESSION['name']; // Relative to the root if (!empty($_FILES)) { $tempFile = $_FILES['Filedata']['tmp_name']; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') .'/'. $_FILES['Filedata']['name']; // Validate the file type $fileTypes = array('m4a','mp3','flac','ogg'); // File extensions $fileParts = pathinfo($_FILES['Filedata']['name']); if (in_array($fileParts['extension'],$fileTypes)) { move_uploaded_file($tempFile,$targetFile); echo '1'; } else { echo 'Invalid file type.'; } } echo $targetFolder; ?> I added Code: [Select] echo $targetFolder; at the bottom so that I could make sure that the string returned was correct, and it is, i.e. '/songs/nick'. For some reason though, uploads are not going to the correct folder, i.e. the username folder, but instead are going to the parent folder 'songs'. The folder for username exists, with correct permissions, and when I manually enter Code: [Select] $targetFolder = '/songs/nick';all works fine. Which strikes me as rather strange. I have limited experience of using php, but wonder how if the correct string is returned by the session variable, the upload works differently than with the manually entered string. Any help would be much appreciated. It's the last issue with a website that was due to go live 2 days ago! Thanks, Nick I require a page to be added to my website. This page will facilitate a refined search via Google, Bing and Yahoo search engine simultaneously , show the top 5 of each engine. Is this possible using php ? Thank's |