preg-replace

preg_replace replace whole string.

Hi, my preg_replace replaces my whole string instead of just the bit where the expression fits. Code: http://beta.yapaste.com/bd This is what I want replaced: <table id=\"post24100391\" style=\"width: 100%;\" class=\"p4\" > Thanks for help. ...

use regular expression in php

..(content)............. <A HREF="http://test.com/content" >test link </A> ...(continue content)... I want to delete link with content. And also text between link. ...

PHP - BBCode parser - Parse both bbcode link tag and not tagged link

Hello to everyone. I need to do this : when a user insert a BBCode tag, with preg_replace and regex i do some trasformation. e.g. function forumBBCode($str){ $format_search=array( '#\[url=(.*?)\](.*?)\[/url\]#i' ); $format_replace=array( '<a class="lforum" target="_blank" href="$1">$2</a>' ); $str=preg_re...

PHP - BBCode parser - recursive [quote] with regex and preg_replace

hello, i'm making my own bbcode parser, and i've a problem when i try to do the recursive quote. this is my code : function forumBBCode($str){ $format_search=array( '#\[quote=(.*?)\](.*?)\[/quote\]#is' ); $format_replace=array( '<blockquote class="quotearea"><i><a class="lblackbu" href="./index.php?status=userview&userv=$1">$1</a> wr...

PHP: question about preg_replace()

Hi, i have found this: $text = preg_replace('/\W+/', '-', $text); Anyone can tell me what exactly do that? There is no information about what '/\W+/' means.. Regards Javi ...

preg replace to remove bbcode quote

Could someone give me an example of how to I can remove [QUOTE=author;3095231] Author being the authors name, and 3095231 being the post. I want to use preg replace, or anything similar but not sure how and was wondering for an example, I believe it would be something like [QUOTE=(.+?)] and i don't know the rest. ...

PHP preg_replace - finding the replacement from an array using the match as the key

I have a string which can contain multiple matches (any word surrounded by percentage marks) and an array of replacements - they key of each replacement being the match of the regex. Some code will probably explain that better... $str = "PHP %foo% my %bar% in!"; $rep = array( 'foo' => 'does', 'bar' => 'head' ); The desired result ...

How do I filter this line "XX<i>\r</i><i>\n</i>" to XX?

Question is in the title. I tried strip_tags, but that shows up blank and I tried using preg_replace, but I don't quite understand the syntax apparently.. Tried this $test = "Home<i>\r</i><i>\n</i>"; $patterns = array(); $patterns[0] = '<i>'; $test = preg_replace($patterns, '', $test); but echo $test is still...

How to remove php code from a string?

I have a string that has php code in it, I need to remove the php code from the string, for example: <?php $db1 = new ps_DB() ?><p>Dummy</p> Should return <p>Dummy</p> And a string with no php for example <p>Dummy</p> should return the same string. I know this can be done with a regular expression, but after 4h I haven't found a sol...

Problem detecting forward slash in preg_replace regex pattern

I am running preg_replace across a string which may contain street numbers. The pattern I'm using is: ([A-Za-z0-9]*)/i This works fine for numbers such as 1, 1a, 123 etc. However it does not pick up street numbers like 1/54B I tried to add a forward slash to the pattern like this: ([A-Za-z0-9\/]*)/i But it isn't picking up number...

What does this Regular Expression Mean

$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); And is there any place I can learn regular expressions? I know the basics. ...

How to append or replace trailing question marks using preg_replace?

I want to enforce single question mark at the and of the string. In JavaScript it works perfectly: var re = /[?7!1]*$/; document.write('lolwut'.replace(re, '?')); document.write('lolwut?'.replace(re, '?')); document.write('lolwut??'.replace(re, '?')); document.write('lolwut???'.replace(re, '?')); document.write('lolwut???!!!11'.replace(...

using preg_replace to add backslash before single quote

How to add a backslash before single quotes using preg_replace() php function ? ...

How would I preg_replace the following?

I've got this snippet of code that I will be replacing in various places and I was wondering how would I write the pattern to preg_replace it? Thanks! <div class="leftside item1"> <label for="item1">Item1</label> </div> I'd like to replace it with: <div class="leftside item1"> <label for="item1">Item1</label> </div> <di...

replace string with javascript using regex

Hi I have text inside "textarea" and I was trying to remove the text between: <textarea></textarea> using replace function with some regex. here is what I did so far: x = '<TEXTAREA style="DISPLAY: none" id=test name=test>teeeeessst!@#$%&*(LKJHGFDMNBVCX</TEXTAREA>'; x.replace('/<TEXTAREA style="DISPLAY: none" id=test name=test>.*</TEXT...

Replace multiple occurences of same symbol using preg_replace?

Hi all, A newbie question: Let's say I have a string like this: $string = "hello---world"; How would I go about replacing the --- with a single hyphen? The string could easily look like this instead: $string = "hello--world----what-up"; The desired result should be: $string = "hello-world-what-up"; ...

Having some trouble with Regex

Ok, so I have this: $fromArray = array( "/(\[color=)(.+)(\])/", "(\[\/color\])"); $toArray = array( "<span style=\"color:\\2\">", "</span>"); What that's supposed to do it match all [color= to . I'm running that, but this is what the source outputs: <span style="color:red]RED<b>BOLD</b>RED[/color"> When I try to run [color=red...

How do I search for and replace a specific area of content in a HTML document using preg_replace

I have a HTML document with the a table which I want to replace, however I don't know what the content of the table will be so I need to search for the opening and closing table tags and then replace the content between them. I'm a bit of a n00b with regular expressions so I'm having trouble working out how to do this... any ideas? Upda...

Using preg_replace without destroying id information

I'm trying to hack about some sidebar code in a Wordpress template I'm developing. Basically I've captured what I need in an output buffer and I'm running regex over it to replace bits with the code I need. Problem is my regex knowledge is just a bit short on what I need to achieve. The problem I'm having is as such: $output = preg_rep...

Help with applying exception in preg_replace

Hello How can I can I allow only digit [^0-9] and a minus sign in front the digit. Example : Valid = -1...-9, Invalid = --1-... ...