str-replace

How to replace multiple %tags% in a string with PHP.

What is the best way of replacing a set of short tags in a PHP string, example: $return = "Hello %name%, thank you for your interest in the %product_name%. %representative_name% will contact you shortly!"; Where I would define that %name% is a certain string, from an array or an object such as: $object->name; $object->product_name; ...

php fopen , str_replace

I need to open a file , replace some content( 12345 with 77348) and save it. As far I have $cookie_file_path=$path."/cookies/shipping-cookie".$unique; $handle = fopen($cookie_file_path, "r+"); $cookie_file_path = str_replace("12345", "77348", $cookie_file_path); fclose($handle); However it doesn't seem to work .... I would app...

PHP encoding problem with Pound Sign

Hey guys, I am retrieving a variable that contains a £ sign from another page. I want to remove this and I have tried using str_replace but I am left with the following: �100. $amount = str_replace('£', '', $amount); Any ideas? ...

Could you tell how to replace by regular expression

Could you tell how to replace string by preg-replace (need regular expression): /user/{parent_id}/{action}/step/1 At the equivalent values of an array: array('parent_id'=>32, 'action'=>'some'); To make: /user/32/some/step/1 Addition This is a typical problem, so I probably will not know what the names of variables come ...

PHP string replace match whole word

Hello, I would like to make a whole word replace using php Example : If I have $text = "Hello hellol hello, Helloz"; and I use $newtext = str_replace("Hello",'NEW',$text); The new text should look like NEW hello1 hello, Helloz PHP returns NEW hello1 hello, NEWz Thanks. ...

replace entites in rawurlencode i.e. < > "

Hi I have the following code <a href="snippet:add?code=<?php echo rawurlencode($snippet->snippet_content); ?>Save snippet</a> where '$snippet = &lt;a rel=&quot;nofollow&quot; href=&quot;http://digg.com/submit?phase=2&amp;amp;url=&amp;lt;?php the_permalink(); ?&gt;&quot; title=&quot;Submit this post to Digg&quot;&gt;Digg this!&lt;/a...

Python string.replace() not replacing characters

Some background information: We have an ancient web-based document database system where I work, almost entirely consisting of MS Office documents with the "normal" extensions (.doc, .xls, .ppt). They are all named based on some sort of arbitrary ID number (i.e. 1245.doc). We're switching to SharePoint and I need to rename all of these f...

how to keep count of replaced strings

I have a massive string im trying to parse as series of tokens in string form, and i found a problem: because many of the strings are alike, sometimes doing string.replace()will cause previously replaced characters to be replaced again. say i have the string being replaced is 'goto' and it gets replaced by '41' (hex) and gets converted ...

str_replace just returns caps

i have a lil problem here..i'm using str_replace to replace the most common words..and for some reason its replacing every letter except caps. for example..if i had the code below $str ="Fat string of Text."; $commonwords = array('fat','of','random'); $cleantext = str_replace($commonwords,'',$str); echo $cleantext; it would echo...

PHP Replace Variables in URL

Hello, I wondered if it was possible to rewrite a URL so designed for the rewrite wrote in htaccess e.g. I have the URL: http://example.com/page.php?page=5&amp;action=something But I want to change the URL to: example.co m/page/5/something This is just for the href, the htaccess bit is solved. ...

PHP str_replace not working correctly

Hi, I'm using str_replace and it's not working correctly. I have a text area, which input is sent with a form. When the data is received by the server, I want to change the new lines to ",". $teams = $_GET["teams"]; $teams = str_replace("\n",",",$teams); echo $teams; Strangely, I receive the following result Chelsea ,real ,Barcelon...

What's the best way to re-process HTML into a single-line string in PHP?

I'm working on a WordPress plugin that exports posts and associated data into a tab-seperated text format. It's almost finished, but I'm struggling to find the best method to re-process HTML into single strings. I'm using a combination of preg_replace and htmlentities, but it's getting a little messy. I'm sure there must be a preferred...

splitting string by €-symbol with PHP won't work!?

hi there! i got this crappy website i need to parse and the html-element i need to get the contents of contains "€" symbols. the actual html of this page looks like this: <td>Mais-Lauch-R&ouml;sti <font color=#000000 size=1>(1,2,9,11)</font> mit Paprikasauce <font color=#000000 size=1>(3,9)</font><nobr><b> 2,10 &euro;</b></nobr><br/>.....

Typographer's quotes in PHP on Yahoo

My client is a small newspaper and provides stories with typographer's quotes instead of "straight" quotes. The stories are assembled into HTML by PHP. On my Apache server, they display fine, but on Yahoo, where my client's site is located, they are all replaced by question marks. To fix this problem, I wrote the following function in P...

PHP Simple way to replace or remove empty lines with str_replace

$line-out = str_replace('\r', '', str_replace('\n', '', $line-in)); The above works for me but, I saw a [\n\r] example somewhere and I cannot seem to find it. I just want to get rid any blank lines. The above is in a foreach loop. Thanks for teaching. ...

ASP.net c# replace string not working

// Build email link confirmLink = Master.siteDomain + "/newsLetter.aspx?action=confirm&e=" + emailAddress + "&code=" + verCode; using (SqlCommand cmd = new SqlCommand("SELECT newRegEmailBody, newRegEmailSubj FROM tblSiteSettings WHERE (isActive = 1)", Master.cn)) { SqlDataReader rdr = cmd.Exec...

Howto change some words into links in HTML?

Hello, I want to change words from list (in file or database) into links in HTML website. I used str_replace, but i have problem with replacing words, that are already in links auchor. eg. I have html like this: Lorem ipsum donor et simet <a>lorem ipsum</a> eta raoa talkesa z uta. An i want to replace all "ipsum" into links, but skip...

how to remove new lines and returns from php string?

A php variable contains the following string: <p>text</p> <p>text2</p> <ul> <li>item1</li> <li>item2</li> </ul> I want to remove all the new line characters in this string so the string will look like this: <p>text</p><p>text2><ul><li>item1</li><li>item2</li></ul> I've tried the following without success: str_replace('\n', '', $st...

Removing content from start and end of string (PHP)

Hi there, I'm trying to get a users ID from a string such as: http://www.abcxyz.com/123456789/ To appear as 123456789 essentially stripping the info up to the first / and also removing the end /. I did have a look around on the net but there seems to be so many solutions but nothing answering both start and end. Thanks :) Update 1 ...