Find And Replace Text In Preg_match Array
I'm trying to change a font color html code once my preg_match_all reads the file. Now the code only shows up when a winner has been posted for that tour. Otherwise it's not visible. So I want to search the preg results which is $matches, for the "font color=3FFF5E" and replace it with "font color=FFFFFF". If the code is not found, continue what it was doing. Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Replace Single Quote Using Preg_match
Since single quotes have security issues during input, I am trying to strip the single quote using preg_match. I am able to replace other characters accept for the single quote. Is the single quote being escaped wrongly? The following is the code snippet.. $patterns[0] = '/'/' $replacements = '' $string = preg_replace($patterns, $replacements, $string);
Preg_match/replace To Fix A Search Query
I am working on a script to handle a search query. In some instances, the query could come through as "isbn:%20#############" (where %20 is an encoded space and the colon is optional). Basically I want to strip off the ISBN portion and leave just the numbers if that is the case. Orignally I was trying $value = $_GET["query"]; if (preg_match("isbn:?%20", $value)) { $isbn = preg_replace("isbn:?%20", "", $value) } else { $isbn = $value }
Find And Replace
Hey there i have an input box but want to know the best way of doing this i want to allow people to enter in website <a href="skdfj"> safasd</a> but would prefer if they could just enter http://bla.com
Generic Find And Replace?
I don't understand preg and i have been trying for quite some time. Is there a find and replace function that just takes parameters and does the work for you? for example: find_replace($strtofind, $strtoreplacewith); when parsing any text editor file (.txt, .php, etc)
Find Replace With Regular Expressions
I'm trying to create a function to perform find and replace on data entered into a form textarea. I tried using str_replace() - but it is a too sloppy for what I need. So I'm thinking regular expressions are the way to go. There are two functions, one is a true find and replace, and the second is a "find and append" (basically finds a word in the string, and then appends another version onto the end of the string.). I've played with it allot, unfortunatly I can't get it to work right. function findreplace() { extract($GLOBALS); $find = "/^" . $_POST['find'] . "$/"; $replace = $_POST['replace']; $PATTERNS = $find; $REPLACEMENTS = $replace; $keywords = preg_replace($PATTERNS, $REPLACEMENTS, $keywords); // $keywords = str_replace($find, $replace, $keywords); return $keywords; } function findappend() { extract($GLOBALS); $find2 = $_POST['find2']; $replace2 = $_POST['replace2']; $PATTERNS = $find2; $REPLACEMENTS = $replace2; $keywords = preg_replace($PATTERNS, $REPLACEMENTS, $keywords); /* $keywords = str_replace($find2, $replace2, $keywords); */ // Append find to then end of the string $keywords .= "" . $find2; return $keywords; } What am I missing?
Find URL And Replace With HTML Hyperlink
I have a database full of user input, some users enter in URLs.. when I display this information, I would like to go through the text, look for URLs and turn those into real hyperlinks... so I need to take http://www.whatever.com and make it a real hyperlink. Am I in the right place? If so, how would I go about doing this? I am using php/mysql and I would like to simply wrap a function around, for instance, my $output variable which holds the data retrieved from a user input.
Find And Replace Query Variable In URI String
I am trying to find and replace the query variable relating to the session id "sid=". This is the portion of the script that has to find out where the sid= is in the string and replace it with an updated version that contains the session id. It is not finding "?s=" nor "&s=" when I run it any of the following urls. http://www.mysite.com/?func=home&sid= http://www.mysite.com/index.php?func=home&sid= http://www.mysite.com/?sid=&func=home http://www.mysite.com/index.php?sid=&func=home I commented out the parts which do not have a bearing on the basic string search function. PHP Code:
Text Replace
I have two paragraphs on a page that I want to replace. I've used preg_match_all() to get these paragraphs into an array. This works without issue and was simple as the paragraphs are between HTML comments. The code's shown below. Code:
How Do I Replace Text In A String...
I have a form setup to take text from a user and insert it into a MySQL database. The problem lies when the user uses an apostrophe in his text. The apostrophe causes the mysql_query statement to end early because it thinks the apostrophe is part of the syntax, not knowing it's only part of the value. Example: If the user submits the text "I'm from the Shire!" when it's submitted to MySQL it thinks the statement ends at I' and thus causes a failed query. How can I escape or process these text strings to avoid this?
Replace Text With An Image?
is there anyway to use file_get_contents to search for a text in a websites source code and then when it finds the text stated it displays an image?
How To Find A Match In A Text Field ?
i am using ereg($rowvalue[0],'humor2')==true to find a match in the text field. how can i find a exact match, ie. the text field contains 'humor,humor2' so, if using ereg the result will be true for both humor and humor2 but only 1 - humor2 is correct. how do i find an exact match ?
Search And Replace In Text File
I have a text file with 30 or so lines. Each line has this format: sometext somevalue. They are separated by a single space. I want to search in the file for "sometext" and replace "somevalue" with a particular string.
Eregi Search And Replace For Some Text
I'm trying to do a search and replace for some text. For example, I have a word that is 'history', I want to replace every occurence of 'history' with: <a href="history.html">history</a> Now, that's easy, I can do that - however, as 'history' could also be 'History', I want to ensure that the format of 'history' stays the same. For example: $strRep = 'history' $str = eregi_replace($strRep, '<a href="history.html">'.$strRep.'</a>, $my_other_string); That's fine - however if history is capitalised (History), then I have a problem: $str = eregi_replace($strRep, '<a href="history.html">'.$strRep.'</a>, $my_other_string); because the above example would lowercase History to history.
Replace A Line In A Text File
I would like to replace a single line in a text file. The initially i only had to have a single line so I could just use fputs to rewrite the entire file. Now I have three lines and want to selectively replace one of them..
How To List/find Html Tags In Text
What I try to do is to search a text for html tags. Why. Because I want to use nl2br on the text, but since this command add br instead of all /n it is not a nice thing to add t.x. a html list inside the text. Of course it is possible to add the list and remove all space between li tags, but this is not so readable to the writer. What I try to do is also to add nl only in the plain text and inside li and td tags. So in the li case I have to find <ul> and </ul> and <table>..
Dictionary Search Definition Replace Of Text
I'm trying to search a weather report for matches to the keys in my associative dictionary array and replace them with the $term => $definition. following is my code. again, any advise appreciated. REF: full php source PHP Code:
Replace Text Outside Html Syntax Regexp Php
how can i replace text outside a html syntax by using reg exps in php? I mean i have a text like <h3>heading</h3> <p>text</p> <table> <tr> <td>cell1</td> <td>cell2</td> </tr> </table> or any html code. now i want all the text outside the syntax (here: heading, text, cell1, cell2) replaced by a special code like <img...>. how can i code a reg exp pattern in php, that replaces each character in the "real text" by an other piece of code, but doesnot change any of the syntax statements?
Strpos To Find Xml Tags To Pull Out The Text Data
I'm trying to use strpos to find these xml tags so I can pull out the text data; but the bracket chars won't let the function work. Is there another way to do this? $php_XML_tag = "<codeFacility>ZNY</codeFacility>"; $pos = strpos($php_XML_tag, '<codeFacility>'); print $pos; results is $pos == 0
Preg_Replace, Replace Bits Of Body Text Such As 'XML' With An Acronym
I've got this: $thebody = preg_replace("/(s¦()".$acronymsfind."()¦s)/",$acronymsreplace,$thebody); I'm trying to replace bits of body text such as 'XML' with an acronym, but I only want to replace the specific acronyms that start with either: - a space (s) - a bracket (( or )) - a speech mark or inverted comma (" ') and may end with a full stop (period - .) I'm not doing right and I've done as much googling and php book reading but still can't do it!
Select Specific Snippet Of Text, Replace With A Database Result
I'm having some problems trying to do something; I just can't think of a way to do it. Basically, I want to search for a specific snippet of text in a body of text, then replace it with the requested database result with some thrown in HTML. Users will be able to type the following (or something along these lines, depending on what works best): [image=12345]Insert caption here[/image] Then I need it to search for the requested image in the appropriate table and return the image's url (for an example, let's say the table is called "images", and the columns required are "imageid" and "imageurl". Code:
Find A Value In An Array
I want to find the smallest value in my array and then write it on the screen wit echo. I thnik that i got the 'founding part' but the number does'nt been writet out on the screen. Code:
Find A Specific Value In An Array
What I want to do is compare a value against an array and perform a specified action if the value is in the array. Specifically, I want to preselect an option in a list based on whether or not the option id is in a field (a 'set' column) of a specific entry in a db. My code so far is: PHP Code:
Find Mysql Row In An Array?
I would like to be able to match values from my mysql table to an array. For example: $result = mysql_query('SELECT * FROM db'); while ($row = mysql_fetch_array($result)) { if ($array == $row[id]){ echo "We found your value"} } I realize this isn't a functional example, but basically I would like to match the id value with the same value in the array and if it doesn't exist go to the next row of the mysql. I've tried a few things such as array_filter, with no success. It seems like theres an easy way to do this that I don't know of.
Find Current Index Value In Array
I am looking for a way to find the numerical index of an array item without coding in a manual count using a foreach. Here is the situation: I am throwing a class a configuration array, where all of the arrays will have the same number of items as follows: PHP Code:
Loop Through Array Find File Extension
i need to build a little script for my browser script... i need to do the following... extract the .ext from the given file name, then i need to pass that to an array that has a list of valid extensions and what icon to use.
Find Prev/Next Vals In Array W/ Named Indices
Hi, I have an array of about 15 values with all named indices. How would I find the previous/next values in the list when given, in a variable, one of those named indices? The Prev/Next values should be based on the order in which they were entered. Thanks.
How Can I Find A Name From One Table In A Text From Another Table?
I have one table with a description field and other info, and I also have another table with a list of names and picture url:s. When I display the text description on my site I'd like to know if there are a match with a name from the 'names' table in the text. Code:
An Array Of Text Boxes
I have the full code in a php script where I essentially display a form with checkboxes, and 2 text boxes associated with each checkbox to record grades ( marks and remarks ). The form displays correctly and the checkboxes I select do pass the correct id numbers for the students to be graded, also the numeric data in the first textbox is correctly transmitted HOWEVER the data in the second textbox gets randomly truncated. e.g, if the "remarks" textbox has 'hello', it gets truncated to 'o'. It seems I'm not resetting something or there is another simple oversight somewhere, perhaps the script treating the data as a string rather than as an array Code:
Matching Text In An Array
I know this is a really easy one, but its been a long day and the old brain has packed up. I've got an array with the main keys for a number of IP addresses, as follows: $IP = array(); $IP[] = "216.239.46."; $IP[] = "216.239.3"; $IP[] = "216.200.130."; $IP[] = "216.35.116"; $IP[] = "216.35.112."; $IP[] = "216.34.121."; Now, the string $ip_address contains the full IP address of someone visiting the site. I want to compare it with the list above and tell if it is a crawler. What code should I use from here? I've tried various things, but found nothing that works reliably. I know I'm missing something obvious and hope somebody will put me straight.
Text Files Into Array
I'm trying to read a text file that has a bunch of names in it into an array so that I can output that array to a comma separated format. My problem is this, I do not know how to make a file go into an array, I've tried the explode function, but all that does is spit out "Resource ID" the format of the file is "1. FirstName LastName" with line breaks so the next line is "2. NewFirstName NewLastName", and so on...
I Need To Addslashes() To The Text Box Array
I need to addslashes() to the text box array that is posted on my page but not sure where is should go within my code. I have the following code: if (isset($_POST['textarea']) && is_array($_POST['textarea'])) { foreach ($_POST['textarea'] as $textid => $textarea) { $q= "update mytable set textfield= '$textarea'"; $r= mysql_query($q); } } If someone could amend the code or highlight where I need to apply addslashes() i would be grateful.
Open A Text File And Put Into Array
I want to open the text file and put it into an array so i can search the contents of the text file.I've figured out how to search an array but cant seem to open a file into an array and then search it. I want to take blah.txt open it insert it into $some array and then use the array_search function to search for the word the user puts into a form.If you can point me to a tutorial, that would be helpfull.This whole search thing is driving me nuts.Opening and writing to files is easy...now searching the files im writing to ??I'm lost.
Create A Delimited Text Array
How can I create a delimited text file to work with this script. I would like to put this first part in a text file and load it into an array so the php script can parse it. Code:
Access An Array From A Text File?
Im trying to build an array from elements I have stored in a text file (So I can access them on multiple pages). What is the syntax for this? I thought it might be... storedArray1 = array(require_once("/arrays/stored_array_1.txt")); or storedArray1 = array(include("/arrays/stored_array_1.txt")); but I guess you can only use the 'include' statement when inserting text into html code NOT php code?
Returning Text Input Type As Array
I'd like to make all the text inputs in this form to be part of an array. The reasoning is that the form is built dynamically so there are times when there are 4 inputs while other times it's 12. When the form is submitted I need those inputs to be error checked and such.
Problem When Serializing Array With Multiline Text
I have a question, or problem if you will, that I'm sure someone knows the answer to. I have a database that stores information on a given user. The information is stored in a serialized array. This works flawlessly when using only single line text. When I tried to store multiline text, the problem arose.
Explode Text Area Into Array For MySQL Table
On my site, I have a textarea where users enter their sites' information in the following format (tab-delimited): Site Name <tab> Site Description <tab> URL <newline> Site Name <tab> Site Description <tab> URL <newline> (and so on...) I know I have to use the "Explode function and a loop to get the data into an array and enter it into a MySQL table. Would anyone have a snippet of code off-hand that could show me how to do this?
Array Query - For Adding Alt Text To Multiple Image Upload Form
I've set up a form for uploading multiple images and I am writing the urls to a database, which is queried and outputs the images on a web page. This works fine, however, I also want to add alt/title text for each image upload but can't quite seem to get it working. I'm pretty new to PHP so my knowledge of how to use arrays is fairly limited. Code:
Preg_match
I am very confused with the preg_match function, I'm trying to check that the input from a text box only contains letters, numbers and spaces, if someone could post the code to make this work and explain it so i understand it would be great, thanks
Preg_match()
can anybody see whats wrong with this? It doesn't turn up any errors it just doesn't do anything. PHP Code:
Preg_match
The way I save URL's to the database and revert them back to a usable URL format sometimes leave me with a small problem. I need to know how I can use preg_match on a URL like this: http://www.myhome.com//blank.gif To say that there is a '//' in the url so use '/images/' instead. What would be the identifier in the preg_match to match the // of the url? preg_match("////",$xt->imgurl())?
Preg_Match
I want to validate a field so that it can only include letters. No spaces, numbers, underscores, etc. I know I use pregmatch, but what do I put in it?
Preg_match
I am having a terrible time writing a script to split $ and 10000 in $10000, I also need to check if this number is a real value. I can use this ereg("^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$","$money") to check to make sure it is a valid number.
Preg_match
I'm trying to pull two items from a log with this layout: [Fri Jan 10 06:02:38 2003] [51 Cavalier] Nasrim (Human) <Spirits of Fire> ZONE: nexus [Fri Jan 10 06:02:38 2003] [56 Revenant] Kreelak (Dark Elf) <Spirits of Fire> ZONE: poknowledge I'm trying to pull just the items in red to an array using preg_match_all(), but I can't seem to figure out the regex pattern to do it. If someone could help me out here I'd appreciate it.
Preg_match
<?php // EXAMPLE 1 $text = "This is Driving me mad"; $check = "Driving"; $ss = "([ ][0-9a-zA-Z ˝',.]{0,30}".$check."[0-9a-zA-Z ˝',.]{0,30}[ ])"; preg_match($ss,$text,$check); echo "result = $check[0]"; //gives a result echo "<br>"; // EXAMPLE 2 $text = "This is Driving me mad"; $check = "driving"; // NOTE CHANGE Driving to driving $ss = "([ ][0-9a-zA-Z ˝',.]{0,30}".$check."[0-9a-zA-Z ˝',.]{0,30}[ ])"; preg_match($ss,$text,$check); echo "result = $check[0]"; // gives nothing. ?> According to php.net /i is required to make it case sensitive, so why is this happening?
Preg_match Help
I dont want it to start with a number? function alphanumeric($alphanumeric_field) { if(!preg_match("/[^a-zA-Z0-9]+$/",$alphanumeric_field)) return TRUE; else return FALSE; }
Preg_match
What I am trying to do is match the <a href=some.php"> , </a> and <img> tags and remove them leaving the the rest. any help would be great.
|