PHP - Replacing A Phrase Containing A Variable
I have phrases in a string with the structure of "Note: some description" I want to replace "Note with (, but how can I replace the second " with )?
Similar TutorialsHello, I have been trying to replace a variable's value inside a function in case it matches a certain criteria but I can't seem to get it right. Let me give an example: Code: [Select] <?php function replace_value($obj) { if($obj==1) { $obj=2; } } $number = 1; replace_value($number); echo $number; So how do I go about making $number = 2, because it still has a value of 1 even after I pas it through the function replace_value. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342776.0 Hey guys. I am trying to strip everything between a key phrase and ending tag but for some reason it is not working. I always get blank data. I've tried many different ways but no luck.
basically I have a script that connect to imap and store emails into MySQL as service tickets. works great but I am trying to strip everything except for user reply because currently if a user reply to an email it re-inserts the entire email into MySQL. I added a key phrase at the top of all outgoing emails .
1. structure looks like this.
--Reply below this line to respond--
------------------------------------------------------------------------------------------------
Email body message...
2. When replying to the message it becomes
New Message reply......
--Reply below this line to respond--
old message body.
3. so I would only like to insert the new reply message only.
This is what I got so far.
$message=strip_tags($message, "<br><div><p><u><hr></section>");
$message=preg_replace("</p>", "br /", $message); $message=preg_replace('#--REPLY above this line to respond--(.*?)</section>)#s', ' ', $message); $message=clean("<br/><hr><u>Received On $rep_date / $from_email</u><br><br/>$message"); it inserts the "Received On date and From but $message is blank. If i remove $message=preg_replace('#--REPLY above this line to respond--(.*?)</section>)#s', ' ', $message); it inserts the entire email Any suggestion on what i am doing wrong? thank you all very much. for example, i want to search for an the string "example@example.com" and erase it. thanks in advance ! Hi there... I am working on a PHP website. And trying to install OpenSSL certificate. I'm running Wamp on Windows 7. I typed the command in command prompt as: Code: [Select] openssl genrsa -aes256 -out pass.key 2048 This command then prompts me to enter the pass key as: Code: [Select] Enter pass phrase for pass.key: But at this point I am unable to type anything in. What do we need to do here to allow the input? do we need to make any changes in any file. Please have a look at the Screenshot attached. Thank you! All comments and feedback are always welcomed Hey, I was just wondering if you could help. I have a search and it only searches for exact phrases. $query="SELECT * FROM table WHERE title like '%$searchfield%' OR description like '%$searchfield%' ORDER BY title LIMIT $offset, $rowsPerPage"; $result=mysql_query($query); I was wondring if I could modify it so that if someone searches for something like 'Peeling a Banana' It seaches for the words 'peeling' and 'banana' and not the whole phrase as one? Thanks Hi, and thanks for any help with this.
I have this but of php i have been trying relentlessly to get working.. for over a month. <?php $abs="one two three four words"; $mT = "testing for matching words"; $words=explode(' ', $abs); //$sf=($words); if (preg_match($words, $mT)) { echo "the url $mT contains a Word"; } else { echo "the url $mT does Not contain a Word"; echo "$words[4]"; } ?>
You see, I get a responce only using the last line "$words[4]", (obviously, because I am pointing it the Matching word, (ie: with [4]) Edited June 9, 2020 by x1705 better description. Please help. I am trying to replace parenthesises () in a string with <>. I tried preg_replace and str_replace, but was not success. Here is what I have for str_replace: $word = "(test)"; $word = str_replace('(', '<', $word); $word = str_replace(array('(', ')'), array('<','>'), $word); Hey guys, I have a quick question. Im going to be making a script that will output the name of a news article along with the poster's name beside it. There is only a certain amount of space where that stuff can go so I want to know how I can make it so that say after 20 characters, it ends and puts "..." beside it. Is this possible with php? How would I do it? hi freaks, still working on my email bot. im currently trying to escape <>-tags to be displayed- but not the browser wont exectute it (i.e. xls-tags) i want them as chars. so whin my $content is like <xsl:stylesheet> <xsl:template match="/"> <more xls...> it shows a stylesheet. i just want the chars. Here is what ive been trying so far: but its bad Code: [Select] <?php $string='<tag> > < asdasf'; $bomb=array( '<', '>', ); $defusal=array( '-', '!', ); $string= preg_replace($bomb,$defusal,$string); echo $string; ?> error: Warning: preg_replace() [function.preg-replace]: No ending matching delimiter '>' found in C:\xampp1\htdocs\code.php on line 13 donno any further now Hello, Is str_replace the best way to go about this? In MYSQL, a html template is stored, such that: Quote <table width="{$width}">lots of other ........</table> This is extract from the database, and stored in a string. I would use eval(), but, any user can update this template, so I need to be able to set which variables will be replaced with what the variable is. Thanks! How come this is not replacing correctly? $rp = strtr($rp,"[TIMES]","<span style='font-family: Times New Roman, Times, serif'>") Hey all, i need a function or a way to replace each letter in a string to a star (*) Thanks If this were an example post in a forum: Code: [Select] $post = '[quote author=james]hello this is a quote[/quote] here is some mor text between the next coming quote [quote author=david]hello this is another quote[/quote]'; What is the best way to replace the [quotes author=x] with opening html tag eg: Code: [Select] <div class="quote"><div class="quoteTitle">author=x</div> And then determine if the next is a [/quote ] is an opener or close quote? And then of course there is the issue of the user deleting a [/quote] or even placing a [/quote] before an open quote... Does anyone know of an example to look at? Hi Guys, I use this function to generate seo friendly names for my products once pulled from the database: function generate_seo_friendly_links($pNM, $pID) { $replacedNM = str_replace(" ", "-", $pNM); $replacedNM = rtrim($replacedNM); $brandNewSEOFriendlyURL = "<a href='$replacedNM-$pID.html'>$pNM</a>"; return $brandNewSEOFriendlyURL; } This works great, the only thing is say a product is stored in the database like: product name it would then be converted to: product-name.html if for example theres 2 spaces: product name it would then be converted to: product--name.html with the 2 "--" so for every space it finds we replace with a "-" etc is there a way i could ignore more than 1 space and always have it like product-name-here.html so the names are more uniformed, i can't think of a way to do it. any help would be appreciated thanks guys Graham //$x = ereg_replace('[-a-z0-9!#$%&\'*+/=?^_`{|}~]+@([.]?[a-zA-Z0-9_/-])*','<a href=\'mailto:\\0\' '.$style.'>\\0</a>',$x); I'm having an issue with users uploading files with a Semi Colon in the file name. I am currently using a script that replaces characters within the file name, however, when I try to add a ";" as invalid characters to replace, it is like the semi-colon just stops the script, as the file does not upload (no errors are displayed). Here's the code I'm working with: $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\],~`-'; $file_name = preg_replace('/[^'.$valid_chars_regex.']|\'.+$/i', "", basename($_FILES[$upload_name]['name'])); if (strlen($file_name) == 0 || strlen($file_name) > $MAX_FILENAME_LENGTH) { HandleError("Invalid file name"); exit(0); } I tried placing the semi colon all over the place in the preg_replace function, but nothing seems to work. How can I do this? I want to be able to replace, let's say, every fifth letter from a string. The string is unknown, though, it could come from database, or a POST form. So I'm unsure if I could use str_replace. I think I may need to use preg_replace(), but I'm not not sure. How can I replace ' and " with str_replace? When I using the following code, I will get error. $string = str_replace(""", "something", $string); |