PHP - Help - Find String Within String Between Pipes ||
Ok... I had typed this post out ONCE already and when I clicked REFRESH IMAGE to get a diff captcha it ERASED MY POST
LMAO this is not my night.... What I need help with is probably more simple then I can even think right now - ive been digging at this for 3 hrs now and im out of time for the night I have a DB Record storing ID's between PIPES | when the initial entry is made in DB it stores it like so |47| NOTE: the number could be different these are ID's number doesnt matter its just between Pipes When the second entry is added its added like so |47||67| say we have a total of 5 Entries |47||67||82||55||69| I need to find ID 82 in that string and it has to be between Pipes Find 82 in data between | and return that ID 82 I am putting between pipes because the ID's can be duplicate digits in different lengths so say I have 8 as my ID and down the string i have another id as 88 -- I cant possibly find the correct ID without some sort of seperation character so i used Pipes soo my end goal is the ability to search and if true or false do action if ($result == $find_id){ echo "ID is there"; }else{ echo "NOT THERE -- Adding it"; } Any help is appreciated guys Thanks SangrelX Similar TutorialsI need to find first digit (any number 0 - 9) in a string. I thing I should be able to use: $NumberPosition = strpos($Source, "/[0-9]/", $NumberPosition+1); but it does not work, wonder what I am doing wrong? Hi all, i have this array $str = array("apple is red", "banana is yellow", "pineaple is tropical fruit", "coconut is also tropical fruit", "grape is violet"); i want to find string "coconut" inside $str and put the whole string "coconut is also tropical fruit" into variable $coconut. can i do this? i don't want to use the this code Code: [Select] <? $coconut = $str[3]; echo "$coconut"; ?> can someone help? Thank you, Best Regards I am making a online Bible with search function. I was able to do the boolean search for text keywords without much trouble. Now I want a user to be able to type in an exact verse into search form and have that verse display in results. IE: User types in John 3:16 and search result displays that verse. The following works if the user types John:3:16. I cannot figure out how to do this without requiring the user to type a : after book name. Code: [Select] if($search_type=='verse'){ $query2 = explode(":", $query); $bookquery = $query2[0]; $chapterquery = $query2[1]; $versequery = $query2[2]; $result4 = $db->sql_query("select * FROM Bible$version WHERE book = '$bookquery' AND chapter= '$chapterquery' AND verse ='$versequery'"); while ($row = $db->sql_fetchrow($result4)) { $book = $row['book']; $chapter = $row['chapter']; $verse = $row['verse']; $scripture = $row['scripture']; echo "<b><a href=\"modules.php?name=Bible&call=chapter&viewbook=$book&viewchapter=$chapter&version=$version\">$book</a> $chapter:$verse</b>"; echo "<br>"; echo "$scripture"; echo "<hr>"; } if(!$query){ echo "<b>You did NOT enter any keywords.</b><br>"; } if(!$scripture){ echo "<b>No results found.</b>"; } } } Is there a function to find first integer in the string and insert a : before it? Is there an easy way to find a numeric value in a string if I don't know what the string will contain? For example I want '52' out of: mystring52 Hopefully there is already a simple function to do this? I'm thinking there may not be as the string having more than one group of numbers may confuse matters. I'm just dealing with abcdef123 or similar in this case though. I have the following variable: $text = "javascript:openimage('http://images.icecat.biz/img/norm/high/5966342-254.jpg',850,850)" Now I want to put the string "http://images.icecat.biz/img/norm/high/5966342-254.jpg" into a variable called $url ( $url = "http://images.icecat.biz/img/norm/high/5966342-254.jpg" ) How do I do this? if i want find included a word in the a range how can i do it? example : Quote array("problem is an obstacle, impediment, difficulty or challenge, or any situation that invites resolution; the resolution of which is recognized as a solutionquestion raised for inquiry, consideration, or solution proposition in mathematics or physics stating something to be done"); how can i find only start 20 charecter and my found word after 20 character by end example :if my word be inquiry i want find :...soluti Quote onquestion raised for inquiryconsideration, or solution proposition... [/size] I have another question related to string searches. What I have is a string of couple thousand characters of all types but the date format is allways the same: dd-mth-year (two digits for day-three letters for month-four digits for year). Can I use the format alone to determine where the date is located which in turn would make it very easy to store that date into variables for inserting into database, etc. Is there anyway to tell php the format to look for or do I have to have actual numbers/letters to perform the search? How can I check this string to see if it has a ~ character using php? Code: [Select] $string = 'userlocation~credentials~specialties'; Hello everyone, I am trying to select and return any rows that have a specific string in it. Let's say I have a column name "item_id" and in every row of that column I have values like so: row A: (11,22,44,34) row B: (12,56,78,98) If the user picks the number '22', I use the following SQL line to get the row in which the number '22' is contained. SELECT * FROM Persons WHERE City LIKE '%22%' and row A gets returned, just like it is suppose to. The problem is, if the user selects a single digit number like '2', both row A and row B gets returned because they both have values that contain the number '2' in it. Instance, row A has the number '22' and row B has the number '12' so both rows get returned when the number '2' is requested. I don't want that, I only want the row that has the exact number '2' or '34' or whatever number I request, to be returned. So to get around this problem, I am wrapping my numbers in letters like so: row A: (a11a,a22a,a44a,a34a) row B: (a12a,a56a,a78a,a98a,a2a) and requesting it like so: SELECT * FROM Persons WHERE City LIKE '%a22a%' My question is: Is there a better way to work out this logic? Hello, I have a few strings that contain dates along with some other text. The string looks like this: Code: [Select] Hi, could you please add these dates to the database?<br /> <br /> <br /> 2-September-2011<br /> 6-September-2011<br /> 7-September-2011<br /> 8-September-2011<br /> 9-September-2011<br /> <br /> Thank you. Dates are always the same format. Sometimes there's a single date, most times there are multiple. Does anyone know how can I get the dates from this string to add them to my sql database? Thank you! Hi
I have a MySql database and wondered if there is a code to search a table field with a given string and display the number of unique occurrences.
The table is asterisk_cdr and would like to know how many calls received daily on a perticular channel.
Thanks
shmideo
Is it pasible to find all occurrences of strings "North" and "North-East" in some txt file and save number of occurrences in some variables?? Hi All, I'm new at php and I need your help. I'm trying to find a string in a website. I want my website to get a string on another website(I have full access) without really opening it on a browser. For example the string is "MyID=123456", i want to find "MyID=123456"(the MyID number is random and always changing but always 6 random numbers) on another website and output only "123456" on my website. Is this possible? Please help. Thanks I wanted to replace a strings in a large text file .. what would be the fastest way ?! e.g the text file contains .. INSERT INTO `subjects` VALUES (1, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (2, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (3, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (4, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (5, 'some text here', 'some text here', 'some text here'); I wanted to replace the string " VALUES (1, " with "VALUES (" in each line .. I'm new in PHP so any response would be much appreciated .. thanks
Hi all dear
<!DOCTYPE html> <html> <body> <?php function generatePermutation($string,$start,$end){ if($start == $end-1){ echo "$string - "; } else{ for($i = $start; $i < $end; $i++){ $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; generatePermutation($string,$start+1,$end); $temp = $string[$start]; $string[$start] = $string[$i]; $string[$i] = $temp; } } } $str = "ABC"; $n = strlen($str); echo "All the permutations of the string a "; generatePermutation($str,0,$n); ?> </body> </html>
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 Hello all, I'm trying to change the end of a javascript call based on the end of the url string. The common part of all the url strings is sobi2Id=, I'm trying to do this with strstr but am having no luck. I'm new to php so my syntax knowledge is terrible! at the moment i've got Code: [Select] <?php $url = $_SERVER['REQUEST_URI']; $tag = strstr ($url, 'sobi2Id='); echo $tag; ?> but this returns an unexpected T_STRING, expecting ',' or ';' Can anyone debug this? I may well be being really silly! Hey there, Thanks for taking the time to read my thread. My issue is that I can't think of a way to edit a XML file using PHP's XML functionality and then assign the edited contents to a string instead of saving the file. Because my issue is that I have to edit the XML file based upon a string brought from a remote location then give it back to that remote location using a string again, to be exact I am doing it via Linux command line utilizing SSH2. This is what I managed to complete on my own. function CheckIVMPConfig($ServerID) { global $Panel; if(is_numeric($ServerID) && $this->IsValidServer($ServerID)) { // We select the game server that the FTP account was created for. $Servers = mysql_query("SELECT * FROM control_servers WHERE server_id = '".mysql_real_escape_string($FTPAccount['ftp_server'])."'"); $Server = mysql_fetch_array($Servers); // Here we select the Box ID that the game server is on. $Boxs = mysql_query("SELECT * FROM control_machines WHERE machine_id = '".$Server['server_machine']."'"); $Box = mysql_fetch_array($Boxs); // Now we select the required package for the box. $Packages = mysql_query("SELECT * FROM control_packages WHERE package_id = '".$Server['server_package']."'"); $Package = mysql_fetch_array($Packages); // Retrive the file. $Config = $CProtocol->exec("cat /home/{$Server['server_id']}/{$Package['package_config']}"); $Parse = SimpleXMLElement($Config); foreach($Parse as $Entry) // loop through our books { if($Entry->port != $Server['server_port']) { // edit the value } else if($Entry->maxplayers > $Server['server_slots']) { // edit the value } } } } This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326004.0 |