preg-replace

Are the PHP preg_functions multibyte safe?

There are no multibyte 'preg' functions available in PHP, so does that mean the default preg_functions are all mb safe? Couldn't find any mention in the php documentation. ...

How to remove diacritics from text?

I am making a swedish website, and swedish letters are å, ä, and ö. I need to make a string entered by a user to become url-safe with PHP. Basically, need to convert all characters to underscore, all EXCEPT these: A-Z, a-z, 1-9 and all swedish should be converted like this: 'å' to 'a' and 'ä' to 'a' and 'ö' to 'o' (just remove the...

preg_replace - array of individual replacements

I am trying to achieve the following: $subject = 'a b a'; $search = 'a'; $replace = '1'; Desired result: Array ( [0] => 1 b a [1] => a b 1 ) Is there any way of achieving this with preg_replace? preg_replace('/\b'.$search.'(?=\s+|$)/u', $replace, array($subject)); will return all the replacments in the same result: Array (...

How do I use preg_match_all with 2 values and preg_replace to create 2 different links

I have a text file that I am displaying in a table. I am using preg_match_all to find a specific Title with a specific Chapter and I am replacing the Title and Chapter with preg_replace to make it a link.. For example the contents within the text file are as follows: Dec 04 20:15 Naruto 123 Dec 04 17:42 Naruto 98 Dec 04 16:19 D Gray Ma...

With PHP how do you output a textfile into a table along with links.

I have this text file: Dec 04 20:15 Naruto 123 Dec 04 17:42 Naruto 98 Dec 04 16:19 D Gray Man 001 Dec 04 16:05 Bleach 128 Dec 04 12:13 50 x 50 44 I need to output the contents into a table with the Date and Time in its own column and the Tile and Chapter in another. Also.. I need to replace the Title and Chapter with a link that must...

With PHP filter a textfile into an A-Z listing

I have a text file that reads: 9123 Bellvue Court 5931 Walnut Creek rd. Andrew Bailey Chris Drew Earl Fred Gerald Henry Ida Jake Koman Larry Manny Nomar Omar Perry Quest Raphael State Telleman Uruvian Vixan Whales Xavier Yellow Zebra What I need to do is I need to create a A-Z listing... so: # A B C D E F G H I J K L M N O P Q R S T ...

What is the business best practice on validating filename?

I have a "dilema" and wonder what is business best practice. I'm using Uploadify to upload images. Now I need to validate the filename before saving the file. I've looked at different solutions, but can't get down to one good solution. Here are my criterias: Filename must be all in lowercase Filename can only contain charaters [a-z0...

PHP regex for filtering out urls from specific domains for use in a vBulletin plug-in

I'm trying to put together a plug-in for vBulletin to filter out links to filesharing sites. But, as I'm sure you often hear, I'm a newb to php let alone regexes. Basically, I'm trying to put together a regex and use a preg_replace to find any urls that are from these domains and replace the entire link with a message that they aren'...

Convert all br tags into one universal <br />

need a simple preg_replace to convert all <br> <br/> and all possible br combinations to <br />. This needs to work in order so i can process a string ie: $output = preg_replace('', '<br />', $input) Thanks everyone! ...

Given an array, how to remove the white spaces before and after a single occuring semicolon & and make other multiple whitespaces turn into one?

Array example entry: test : title=Diet Coke Becomes test:title=Diet Coke ...

In PHP, make every letter left of colon lowercase w/o use of explode,implode

Can this be done with regular expressions? Examples x-example-HEADER:teSt becomes x-example-header:teSt y-exaMPLE:testoneTWOthree becomes y-example:testoneTWOthree ...

Matching the first <p> that does not start with an image in regexp

In PHP, I'm trying to match the first paragraph tag that is not immediately followed by an <img> tag, and add a class to that paragraph tag. For example, it would add a class to: <p>Text</p> and <p><strong>Strong text</strong></p> but not: <p><img src="" /></p> Here's what I have so far which successfully adds a class to the fi...

PHP syntax error on preg_replace method

Hello, I'm trying to do a bbcode parser class that can create personalyzed tags, but I have some problem with urls I've did all I need without particular problems thanks to regular expressions but I have a problem when I try to create a special tag who point to a specified URL. In my class I've added a method like this: <? private...

preg_replace to remove empty tags but keep the end of blockquotes

Hi, I made this expression to remove all empty (inluding tags with just whitespace) tags in the page. $content = preg_replace('/<[^\/>]*>([\s]?)*<\/[^>]*>/', '', $content); It worked a treat until it had to deal with content like this... <blockquote> <p >foo bar</p> </blockquote> <p ><a href="image.jpg" rel="lightbox" title=""><im...

RegEx, preg_replace_callback Question PHP

This is what I've got for for my RegEx, I was wondering if this is the best way. I want to be able to find something similar regardless of the spacing between Identifiers and not be case sensitive. And if possible, not worry about order.. Example: [Foreclosure ="Remax" URL="http://www.remax.com" Title = "4 Bedroom 2 Bath Condo"] [F...

PHP: Correct regular expression for making every letter left of the first colon lowercase

$value='x-Cem-Date:Wed, 16 Dec 2009 15:42:28 GMT'; Right now I have: $value = preg_replace('/(^.+)(?=:)/e', "strtolower('\\1')", $value); this outputs $value='x-cem-date:wed, 16 dec 2009 15:42:28 GMT'; it should output: $value='x-cem-date:Wed, 16 Dec 2009 15:42:28 GMT'; ...

PHP preg_replace: help me grok (?=:)

In another question, there are the following lines: $value='x-Cem-Date:Wed, 16 Dec 2009 15:42:28 GMT'; $value = preg_replace('/(^.+?)(?=:)/e', "strtolower('\\1')", $value); // yields 'x-cem-date:Wed, 16 Dec 2009 15:42:28 GMT' That (?=:) bit indicates a search for the colon, it has to. But, I don't understand that particular syntax, w...

PHP - preg_replace with multiple matches

Let's say I have a string like: $text = "<object>item_id1a2b3</object>xxx<object>item_id4c5d6</object>" I want to convert it to: %ITEM:1a2b3xxx%ITEM:4c5d6 Here's what I've got: $text = preg_replace("/<object.*item_id([a-zA-Z0-9]+).*<\/object/","%ITEM:$1",$text); This isn't quite right, as the search is greedy. Thoughts? Than...

Problem with function call inside preg_replace.

Does not work, the $1-value is lost when calling the function: echo preg_replace('"\b(http://\S+)"', '<a href="$1">'.findTopDomain('$1').'</a>', $text); Works fine, outputs: stackoverflow.com echo preg_replace('"\b(http://\S+)"', '<a href="$1">'.findTopDomain('http://stackoverflow.com/questions/ask').'&lt;/a&gt;' , $text); I need t...

preg_replace() called with arrays needs ksort() beforehand? Huh?

I was working a bit with preg_replace over the weekend and I was reading the Php preg_replace documentation when I saw something odd. Example #2 from the docs shows that when given the following php code <?php $string = 'The quick brown fox jumped over the lazy dog.'; $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; $patterns[2] = ...