I have text like this from poker software (I have highlighted the parts I need to replace).
--- FLOP --- [Jh 9h Ah]
driverseati checks
darrington has 15 seconds left to act
darrington bets 100
InvisibleEnigma calls 100
driverseati folds
--- TURN --- [Jh 9h Ah] [3c]
darrington bets 200
InvisibleEnigma calls 200
--- R...
I'm a little confused. I am running all my inputs through a basic sanitize function I write to only allow certain characters, but characters such as [] are still being allowed.
function sanitize($input) {
$pattern = "/[^a-zA-z0-9_-]/";
$filtered = preg_replace($pattern, "", $input);
return $filtered;}
Any idea why it's doing that?
...
Hi need to change the function ereg_replace("[\]", "", $theData) to preg_replace
...
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&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.
...
I'm trying to convert URLs, but not if they come after src=". So far, I have this...
return preg_replace('@(?!^src=")(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@', '<a href="$1" target="_blank">$1</a>', $s);
It converts the URL, but even if it is before src="
...
why this code does not work ?
$mx['foo'] = "vvv";
$string = "foo is foobar, baz is widgets";
echo preg_replace("/(foo)/ei", "$mx[('\\1')]", $string );
the output must like this
vvv is vvvbar, baz is widgets
...
I am parsing the input of ls -lb and trying to put each field into an array in PHP.
My input looks something like this:
-rwx------ 1 user.name users 546879 2008-09-05 09:23 Newspaper_Templates.pdf
-rwx------ 1 user.name users 403968 2009-01-12 14:16 P2_05.ppt
-rwx------ 1 user.name users 144896 2009-01-12 14:08 P2.5_Using_CRO...
Hi everyone, I'm trying to replace video{79345394} (random number inside the brackets) with a link. So far I have...
preg_replace('@video[{]([0-9])[}]@', $language[61].'<br /><a href="javascript:videoWith($1);">'.$language[62].'</a>', $chat_message);
It doesn't seem to be working, so help is very much appreciated!
...
Hi, I have some content that I am trying to parse...
I have html and with in the html I want to replace all my img tags with a custom string. Now one of the problems I have is that some content that comes in: the image tags is between a anchor.
ex.
<a href="link"><img></a>
The following code I have works...but I want it to be option...
preg_replace('/http:///ftp:///', 'https://', $value);
http:// and ftp:// inside $value should be replaced with https://
This code gives error:
preg_replace() [function.preg-replace]: Unknown modifier '/'
What is a true regex for this task?
...
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...
I am creating some RSS feeds using PHP (5.2) from a MySQL db specifically for an iPhone app I am making through AppMakr.
They are taken from articles on a website which contain images embedded in them, however in the feeds they don't look great. What I want to try and do is whenever there is an image surround it in <p> so they are on th...
want to replace some words on the fly on my website.
$pattern = '/\bWord\b/i';
$content = preg_replace($pattern,'Replacement',$content);
That works so far. But now i want only change the the words which are inside
div id="content"
How do i do that?
...
Hi,
i want to preg_replace "Word" in PHP.
$ret = 'I gave my Word to you.';
$pattern = '/\bWord\b/i';
$ret = preg_replace($pattern,"Heart",$ret);
// echo $ret; = "I gave my Heart to you";
This works so far. But if the sentence is "I gave you my Word." or "I gave you my Word!" it doesn't change the "Word." into "Heart....
I'm working in Wordpress and need to be able to remove images and empty paragraphs. So far, I've found out how to remove images without a problem. But, I then need to remove empty paragraph tags. I'm using PHP preg_replace to handle the regex functions.
So, as an example, I have the string:
<p style="text-align:center;"><img src="http:...
How do I:
replace characters in a word using preg_replace() but make
an exception if they are part of a
certain word.
replace an uppercase character with an
uppercase replacement even if the
replacement is lowercase and vice
versa.
example:
$string = 'Newton, Einstein and Edison. end';
echo preg_replace('/n/i', '<b>n</b>', $st...
How do I address special characters in Regex? @ ? # $ % %...
this patten searches for a letter that comes between a prefix and a suffix.
$pattern = '/((?<!\b$PREFIX)$LETTER|$LETTER(?!$SUFFIX\b))/i';
$string = 'end';
$prefix = 'e';
$letter = 'n';
$suffix = 'd';
But what if $string began with a #
$string = '#end';
$prefix = ?...
I've converted some eregs to preg_matches by replacing the initial ^ and final $ with /s (I hope that was sufficient), but I have an ereg_replace in the same function that I'm not sure about.
It's from a checkPostcode function to be found here.
// Take account of the special BFPO c/o format
$postcode = ereg_replace ('C\/O', 'c/o ', $po...
I am sorting through some lines and some contain email, some don't.
I need to remove all lines less than 6 characters.
I did a little surfing and found no solid answers so, I tried to write my first expression.
Please tell me if this will work. Did I get it right?
$six-or-more = preg_replace("!\b\w{1,5}\b!", "", $line-in);
Followe...
Getting frustrated...
So, I want to modify the back reference of a preg_replace. Figured I can't actually modify (?) so am wondering if it's possible to change the regex to achieve same result.
Example. Match [xx_xx] and output "xx_xx" and "xx xx". The "xx_xx" is straightforward (as follows) but the "xx xx" ?
$y = "this [fishing_rod]...