preg-replace

PHP DOM element string breaks with strtotime() or preg_replace()

I'm using PHP to get XML from an API (Say that 3 times fast). I'm getting all of the correct strings returned from all of the data. The problem comes when I try to reformat the time string with the following two methods: $dataset = $xmlDoc->getElementsByTagName( "Class" ); foreach( $dataset as $row ) { $xmlStartTimes = $row->getEl...

PHP str_replace/preg_replace problem with php open tags

I'm trying to replace something like: $text = "Hello <--name--> !!"; echo str_replace("--","?",$text); Expected: Hello <?name?> !! Result: Hello !! (I'm checking the source code, and I have short open tags enabled) I have tried so many ways but it seems that I can't never have as result any <? (or <?php) string. I think it may ...

preg_replace array: mask regex characters problem

I want to replace word groups by links. The word groups are defined in a multi-dimensional array. There will be thousands of terms to be replaced, so an unindexed, light-weight and multi-dimensional array is needed. Nothing should be replaced when the term is followed by brackets or inside square brackets. Problem: The regex itself w...

preg_replace with parentheses

In PHP my string looks like this: "{{edit(3)}}". I would like the result to be: "open3close", using preg_replace or another method. Any ideas? ...

Php preg_replace

This function doesn't work: function remove_ul($ul) { $ul = preg_replace('/<ul id="general-nav">/', '<ul class="nav">', $ul, 1); $ul = preg_replace('/</ul>/', '<li class="blank"></li></ul>', $ul, 1); return $ul; } I think because of repeating / on line with </ul> Any idea? Thanks. ...

Replace names in text with links

I want to replace names in a text with a link to there profile. $text = "text with names in it (John) and Jacob."; $namesArray("John", "John Plummer", "Jacob", etc...); $LinksArray("<a href='/john_plom'>%s</a>", "<a href='/john_plom'>%s</a>", "<a href='/jacob_d'>%s</a>", etc..); //%s shout stay the the same as the input of the $text. ...

Replace Links Location (href='...')

Hello, I would like to replace the link location (of anchor tag) of a page as follows. Sample Input: text text text <a href='http://test1.com/'&gt; click </a> text text other text <a class='links' href="gallery.html" title='Look at the gallery'> Gallery</a> more text Sample Output text text text <a href='http://example.com/p.php?q=...

replace words in text ignore urls

i use this line to search for a name in text with url's. $name = "xxx"; $text = "my name is xxx en my website is http://xxx.something.com"; $text = preg_replace("/\b(".preg_quote($name, "/").")\b/i", $url, $text); how can i change this regex to ignore urls in the text ...

reg. exp. find tag with attribute

hi there, i need a reg exp (to do a preg_replace) to find all <font> tags with a style="..." attribute... the problem is that i need to match ONLY the <font> with a style attribute AND a value of "height: 0;overflow: hidden;width: 0; position: absolute;"... another problem, the style attribute may be in different positions; ex. <...

Replace &Aring; with something else...

How can I replace &Aring; with some other string using preg_replace? Thanks! ...

Preg Replace question PHP

Im new to Preg Replace and Ive been trying to get this to work, i couldn't so StackOverflow is my last chance. I have a string with afew of these ('pm_IDHERE', 'NameHere');"> I want it to be replaced with nothing, so it would require 2 wildcards for NameHere and pm_IDHERE but ive tried it and failed myself, so could someone give me ...

PHP: replacing a specific char in a range with preg_replace

Hi everybody! Lets say I'm trying to replace every "A" character with a "B", inside two [lol] tags. For example: "[lol]It's greatA really isA[/lol]" will become "[lol]It's greatB really isB[/lol]" I was trying to work something myself but it was in vain. The closest i got is this: preg_replace("%(\[lol\])"."(.*?)([A]+?)(.*?)"."(\[/...

unicode preg_replace problem in php

I've got the string $result = "bei einer Temperatur, die etwa 20 bis 60°C unterhalb des Schmelzpunktes der kristallinen Modifikation" which comes straight from a MySQL table. The table, and the php headers are both set to UTF-8 I want to strip the 'degree' symbol: http://en.wikipedia.org/wiki/Degree_symbol and replace it with the wor...

regular expression and forward slash

i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" . Even using preg_quote($find,'/'), which escapes it, i still get the message: Unknown modifier 't' in /frontend.functions.php on line 71 If i print the find pattern, it shows ...

preg replace in CGI, PL

I want to do preg replace in CGI. I have a string with URL like "www.example.com/data/example.cgi?name=example". I want to write a script which will replace "/data/example.cgi" from above url to "/example.php" ...

How to using replace with variable?

$aaa = preg_replace('/<%var.\$(fullname).%>/is', $_SESSION["\1"], $aaa); ...

prematch for replace html tags

...

preg_replace question

Hello I'm trying to do the following: Say I have an input string like this {stackoverflow is a {cool|great} website|stackoverflow is the {best|greatest}}. {stackoverflow is for {cool|great} coders|stackoverflow is the {best|greatest} site for coders} How can I convert it to the following format by using PHP {stackoverflow is a [cool...

Reg exp to Null/empty string if string contains non alphanumeric characters

Hey Guys, I'm looking for a php preg replace to null/empty string if string contains any non alphanumeric characters or spaces e.g. Strings $string = "This string is ok"; $string = "Thi$ string is NOT ok, and should be emptied" When I say emptied/nulled I mean it will make the string "". So basically anything a-z A-Z 0-9 or space ...

PHP replace text in variable

$image variable gives this code (when echo is used): <img src="/image.png" width="100" height="147" alt="" class="some_class" /> width, height, src and class attributes can be different. What should we do: remove width and height from $image replace alt="" with alt="Poster" Thanks. ...