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?
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Partially Replace A String With Data From The Same String...
I'm trying to write a script to help import some old HTML files as blog post for my website, these HTML files are 300-2000 lines long. I am currently using fgets() to read the files one line at a time, clean them and write them to the database in the appropriate format once the entire article is completed. My issue is many of the links included on these post no longer exist (some date into the '90s) and I want as part of my importing function to "fix" these links as so. 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:
String Replace?
I was using this function to replace some code inside my scripts: $title = ereg_replace( "_", " ", $string[0]); but now I only need to add another character at the end of this $title string. How would I go about doing that?
String Replace
all i need to replace a space in a string of code... basically when it creates this link it calls up the state name Like "New Mexico", how would i replace the space in New Mexico making it newmexico. my code is below. <a href="<?php echo(urlencode($_GET['state2']));?>/<?php echo(urlencode($_GET['city2']));?>main.php?state2=<?php echo(urlencode($_GET['state2']));?>&city2=<?php echo(urlencode($_GET['city2']));?>"></a>
Help With String Replace...
I've got the problem with string replace, i've got a string like: /adsf/sdfd34/sdf/435ff/sdfdf and i need to delete the last characters before "/", so it would become: /adsf/sdfd34/sdf/435ff/ I am trying to make a file manager of a sort, and need to make a link "UP", which would take the user up one level in a directory... I tried to use str_replace, seems its not the one, thn i tried to use preg_replace, seems it is the one i need, but i'm nowhere near there... Thats my last effort: $output = preg_replace("/(/*$)/","/", $input);
String Replace
I am in the process of writing a script to process a file that is outputted by another program we are writing. We are exporting the file to a plain text file in the following format "ID", "Title", "Filename", "AID", "arID", "size", "bit", "Freq", "Dur", "Path", "Owner", "Gr", "date" My problem is, I need to read in each line, whoch I am currently doing with fgets and convert the above into mysql insert statements. What I was thinking that I need to to is to the above string is:- 1. Convert all " to ' using ereg_replace() 2. Addslashes to string to escape any special characters 3. Wrap with insert statement 4. Write to Database However thinking about that process, once I addslashes, all ' will then be ' So the final insert statement would look like :- 'ID', 'Title', 'Filename', 'AID', 'arID', 'size', 'bit', 'Freq', 'Dur', 'Path', 'Owner', 'Gr', 'date' and any other character inside some of those fields whoch are also escaped. Is this going to cause any major problems when inserting into DB?? Should I add an extra step in there some where to convert all " to someting allowed, addslashes then change the previous step back to ' for the insert statement?
String Replace
I have a string like below. $string = "Inner peace, which is peace of mind, is not the sole possession of yogis and hermits. You too can enjoy it without becoming a yogi or a hermit. Click here to read the article." I have to replace "Click here blablab" with ""; But we cannt guess the words followed by "Click here" so i need to replace a sub string which starts with "Click here or click here" and ends with ". or !"
String Replace Help With A URL
I have a form field that will allow a user to post their website for outside linking I want to make sure that the http:// is always present so when i link to it links outside my site. However I want to make sure there aren't links to ftp:// or https:// and that the http:// is always present any ideas? I'm bad at regex but i'm sure someone knows a way?
String Replace
I have a string containg a S sign. How can I remove it?
String Replace
say i have an array $var = array('name' => 'mark', 'city' => 'some city'); ...etc and i have a block of text "Hi <[name]>, do you live in <[city]>?" how should i efficiently replace the <[]> vars with their matching key vals in my array?
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?
Replace Bad Words From A String
Want to replace bad words from a string.I have a list of bad words and allowed words in an array. For example,$allowedwords = array ("*inner", "*outer"); $badwords = array ("inner", "outer"); I want to remove the bad words and similar to bad words and allowed those allowed words similar to bad word.example string: This is an inner text in *inner with spinner.Output like : This is an **** text in *inner with sp****.
Replace String Using Wildcards
I am trying to remove some tags from an XML document that I do not need. <string id="4466.8" encoding="repr">email</string> I want to remove the whole tag for the string but keep the content in the middle, the problem is that the id changes, so is there a way to use a 'wildcard' character in the replace code to replace any character found? $data=str_replace('<stringid="4466.8" encoding="repr">', ' ', $data); I saw a post that /S should work for any non whitespace character, this does not seem to work though... any idea's?
Replace Part Of String
just found a problem with part of my project if a ' is present then it screws up the sql query- so, i need toget rid of it, would the best way be to, use regex, and see if string a contains a ' || string b etc and if so, use str_replace("'","",$string);
Search And Replace In String
Im using the following to search for charictors in a string that are causing problems, and placing a infrount of them. Im trying to do it using: <?php $str = "string's"; $invalied_chars = array(" ", "'"); $result = str_replace($invalied_chars, "", $str); echo $result; ?> The bit im confused by was how to keep the old charictor, just proceeding it with a rather then replacing it?
Wildcard For String Replace
In the following code I need to replace SOMENAME with a wildcard. SOMENAME changes on a regular basis so I have no constant. Code:
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..
Better Method For Search And Replace In String
Here is an example of the type of string I am trying to search and replace, Generic text about *2nothing~ in particular. Just need to *5extract certain~ characters out of the text. I need to search the string for "*", collect the number directly after the "*", then extract the text, and watch for the "~" character to denote the end of the text. Then the information is sent to a new function i.e. new("2", "nothing") The new function formats the data and returns it into the original string. Currently I am just looping through the string and replacing as I go, but I imagine their is a better and more efficient way.
Replace Part Of String In Between Two Other Parts?
I'm trying to do is an str_replace or something within only a set of other strings. What I'm doing with some text that I put into a database is added a <br> whenever the ASCI character 10 (carraige return) comes up. It's like this. $text = eregi_replace(10, "<BR>", $text); what keeps happening though, is that when I make an HTML table in the text, it adds a <br> to that too, and since it's inside the table, it just adds the newline to outside of the table or something and screws everything up. So, what I want to do is only have it replace the newline with a <br> if it isn't inside of a <table></table> string. I've been all over the PHP documentation and have yet to see something that might work.
Remove/replace Coontents From A String
I have a string variable that holds the content of an HTML page. I want to remove/replace all the data inside the html comment tag.[ie. everything between <!-- and -->]This is because I want to do some validation. So I should remove the unwanted data.Do u know how to do it in PHP?
How To Replace An Item In The Url Search String
Using PHP 4, what is the most elegant way to replace a parameter value in a url query string? I want to replace the "Order" parameter, but it could occur anywhere in the query string. myfile.php?Param1=Hi+there&Order=ColumnA&Param3=Bye+Bye myfile.php?Order=ColumnA myfile.php?Param1=Anotehr+example&Order=ColumnA after applying this function, I'd like the result of the above examples to be myfile.php?Param1=Hi+there&Order=ColumnB&Param3=Bye+Bye myfile.php?Order=ColumnB myfile.php?Param1=Anotehr+example&Order=ColumnB
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?
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:
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:
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:
Replace Hex Number Or Decimal Number In A String ?
String may contain alphanumeric values. What is the bestway to replace a hex number such as 0x122aaa and decimal number such as 5678 with a string "blah" Example: I want to replace below-- wr_thru1 data or mask mismatch!! for addr=0x00000b73a0540 & mdfid:11 with wr_thru1 data or mask mismatch!! for addr=hexVal & mdfid:decVal
Getting Text From The Middle Of A String
I have a text file that I'm going to load into a variable. What I want to do is create a second varibale that contains the comments from the html in the text file so any time it finds <!-- it will put the text afterwards into the comment variable untill it reaches --> and then it will stop.
Removing Text From A String
Is there a way to remove text from the beginning of a string up to (and including ) a keyword, then including and after another keyword? Use the following sentence as an example. This is a test sentence that I wish to automatically change. keyword 1 = test keyword 2 = automatically so it reads 'sentence that I wish to' My guess is the answer lies in the regular expression area but I am unsure.
Search A String Of Text...
I would like to search a string of text for "x" if "x" is found then it echo's something, else it echo's something else... Anyways I'm kind of lost as to the best way to search a string of text (for example "1,2,3,4,5,6,7,8,9,10,11,12") and find lets say "7,"...
Search Through A String For Various Text
My users enter text into a database field in the form of: this file {link:afile.pdf} is big and this file {link:another.doc} is small. I have no idea how many times they may enter {link:xxx} into a given field. The code we worked out (see other post below) fabulously translates the text into a hyperlink. The problem is that no matter how often the {link:xxx} is in a given field, I only ever get the first file returned; i.e: This file afile.pdf is big and this file afile.pdf is small. But what I should get is, obviously: This file afile.pdf is big and this file another.doc is small. I need to use some kind of looping function, or a foreach type function. Does anyone have any clues? Code:
How To Duplicate A Text String?
What code do I use to duplicate a text string? For example I have: $activ = md5( $activ );The thing is, I want to take $activ and convert into md5 hash and store it AND store it in the original format. As of now, all I have it is that it is converting into md5 hash and storing it that way.
Long URL With Query String For Use On Text Emails Breaks At '+'
I am trying to send members of a site periodic emails containing links back to the site. I will use HTML and text email but in the text email I have to display the whole ugly URL in order for it to hyperlink. This is OK until I encounter a text field with more than one word. I have tried urlencoding, but the link as displayed on the email is always broken at the '+' sign between 2 words, and doesn't lead anywhere useful. Code:
Removing Html Anchors From POST'ed Text String
I am having problems with trying to remove some tags using PHP. What I want is to perform a search and replace on a URL, so if someone tried to put a URL into a guestbook database, instead of the user inputting a link as: <a href="http://whatever.com">visit me</A> It goes into the database as: http://whatever.com I have tried the str_replace() function, but doesn't seem to work. I have also tried strip_tags() but then that just give the result: This is the code I've written. $AmendedComment = str_replace("<a href="", " ", $_POST['Comment']); $FinalComment = addslashes($AmendedComment); Checking the database and reading it out again, the first part of the URL remains intact, so the URL is clickable - not what I want. I've made an attempt at preg_replace() but it's difficult to get head around trying to write a pattern.
Stripping Html Text And Newline Characters From String
I have used the strip_tags function to remove html from a string with reasonable success. But it still leaves /r/n characters. I've hunted around on various forums for solutions, and every time someone suggests a solution, it actually doesnt work. Code:
Make Text String Read From Right To Left In Imagettftext() Function
I want to write a text string from right to left instead of from left to right with the imagettftext (); function I read in teh manual that the angle variable controls this, it says that 0 angle means left to right, so I tried 180, 360 but nothing happens What angle do I need to put it to get it to write it right to left I am writing a hebrew text string with a font.ttf that supports hebrew characters <?php $white = imagecolorallocate($background, 255, 255, 255); $fontfile = "davidtr.ttf"; $string = "מחלדגכ"; imagettftext($background, 12, 360, 3, 17, $white, $fontfile, $string); ?>
String Of Text (Number Of Pixels / Pixel Size / Pixel Length)
If I'm putting together a list of links and I want to get add each item one at a time inside a foreach($aNames as $sName) loop, is there an easy way to get the number of pixels that the $aName takes up? For instance, in creating a set of links... foreach($aLinks as $sLink) { if ((pixelsize($sLink, $sFont, $iFontSize) . pixelsize($sHTML . " ", $sFont, $iFontSize)) < 400) { $sHTML .= " " . $sLink; } else { $sHTML .= "<br /> " . $sLink; } } The goal is to keep the whole link on one and only one line letting the browser automatically break up any given link..
|