preg-replace

PHP: How to Remove Space Additionally to the Special Chars?

Hello, in my functions.php if have this code: echo '<a href="' . preg_replace('/\s/', '-', $search) . '-keyword1.html">' . urldecode ($search) . '</a>'; this removes the special chars.. but how can i additonally add remove space and replace it with - and remove " so, if someone types in "yo! here" i want yo-here thank you! ...

Link to text PHP

I'm already using this which I found on the net, for whenever I want to edit the information and there is already a converted link which is done by adding a new post, I need this to remove the link into text then when it's submitted to be updated, it will use this function to convert it into a link. function Links($text) { $text = ...

Small regex question in PHP

Hi, I'm trying everything in a string BUT a certain pattern. My pattern is: $pattern = "/^[a-zA-Z0-9]+$/D"; And I want to do the following: $string = preg_replace(anything but $pattern, "", $string); How do I do that? Thanks! ...

preg_replace: replacing using %

Hi all, I'm using the function preg_replace but I cannot figure out how to make it work, the function just doesn't seem to work for me. What I'm trying to do is to convert a string into a link if any word contains the % (percentage) character. For instance if I have the string "go to %mysite", I'd like to convert the mysite word into a...

PHP's preg_split question

I want to split text by the letter-followed-by-period rule. So I do this: $text = 'One two. Three test. And yet another one'; $splitted_text = preg_split("/\w\./", $text); print_r($splitted_text); Then I get this: Array ( [0] => One tw [1] => Three tes [2] => And yet another one ) But I do need it to be like this: Array ( [0] => O...

replace characters that are enclosed with quotes regexp

How can I replace characters with preg_replace, that are enclosed in quotes. I need to replace all special characters, that are in href="" things. example: <a href="ööbik">ööbik</a> should become <a href="oobik">ööbik</a> ...

preg_replace hell

I'm trying to use preg_replace to get some data from a remote page, but I'm having a bit of an issue when it comes to sorting out the pattern. function getData($Url){ $str = file_get_contents($Url); if(strlen($str)>0){ preg_match("/\<span class=\"SectionHeader\"\>title\</span>/<br/>/\<div class=\"header2\"\>(.*)\</div\></span\>/",$s...

Encoding problem with preg_replace() and scandir()

Hi, On OS-X (PHP5.2.11) I have a file: siësta.doc (and thousand other with Unicode filenames) and I want to convert the file names to a web-consumable format (a-zA-Z0-9.). If I hardcode the file name above I can do the right conversion: <?php $file = 'siësta.doc'; echo preg_replace("/[^a-zA-Z0-9.]/u", '_', $file); // Output: si_s...

Regular Expression to identify classes/ids in a CSS file that have no contents

I'm in the process of updating some old CSS files in our systems, and we have a bunch that have lots of empty classes simply taking up space in the file. I'd love to learn how to write Regular expressions, but I just don't get them. I'm hoping the more I expose myself to them (with a little more cohesive explanation), the more I'll end u...

PHP Regular expression flags

Can someone explain what the 'e' flag does, or link me to somewhere that does? I couldn't find anything via google. Example: preg_replace("/a(b?)c/e", "search_foo_term('\$1')", $str); ...

PHP RegEx: How to Stripe Whitespace Between Two Strings

I have been trying to write a regex that will remove whitespace following a semicolon (';') when it is between both an open and close curly brace ('{','}'). I've gotten somewhere but haven't been able to pull it off. Here what I've got: <?php $output = '@import url("/home/style/nav.css"); body{color:#777; background:#222 url("/home/st...

PHP : Pattern Replacement Query.

Currently I have Input: e.g., '123456789'.'+'.'987654321' Desired Pattern: Output: e.g., '123456789987654321' How can I achieve this using in php ? I am not through on regex and so what regex would go in preg_replace for this ? ...

php preg_replace with php code

I have a function that finds a regex thingy, then replaces with php code. I want to have it replace the found regex with php code on the screen, like have it echo out ". except when it echos that in the source, it shows all the <?php tags and echo and everything, and doesnt just output 'wat'. no im not going to just replace the text with...

replace string in preg_replace

<?php $a="php.net s earch for in the all php.net sites this mirror only function list online documentation bug database Site News Archive All Changelogs just pear.php.net just pecl.php.net just talks.php.net general mailing list developer mailing list documentation mailing list What is PHP? PHP is a widely-u...

Regex to Match White Space or End of String

I'm trying to find every instance of @username in comment text and replace it with a link. Here's my PHP so far: $comment = preg_replace('/@(.+?)\s/', '<a href="/users/${1}/">@${1}</a> ', $comment); The only problem is the regex is dependent upon there being whitespace after the @username reference. Can anyone help me tweak this so it...

preg_replace Pattern

Hey Guys, i'm not very firm with preg_replace - in other Words i do not really understand - so i hope you can help me. I have a string in a Text like this one: [demo category=1] and want to replace with the Content of Category (id=1) e.g. "This is the Content of my first Category" This is my startpoint Pattern - that's all i have: '/...

stripping a query string with php (preg_replace)

http://www.chuckecheese.com/rotator.php?cheese=4&amp;id=1 I want to take out the id, leaving the cheese to stand alone. I tried: $qs = preg_replace("[^&id=*]" ,'',$_SERVER[QUERY_STRING]); But that said I was using an improper modifier. I want to remove "$id=" and whatever number comes after it. Are regexp really as hard as they se...

PHP preg_replace html comments with empty space

Hi Guys, I have a bit of php code like this: $test = "<!--my comment goes here--> Hello World"; Now i want to strip the whole html comment from the string, i know i need to use preg_replace, but now sure on the regex to go in there. Can anybody help? Thanks ...

Using preg_replace in mysql

I have a CMS content in database. The content contains '<img src= .............../>' also. I want to retrieve this content using mysql query and show on frontend but with all '<img src='.........../>' removed from the content. How can it be done using query in mysql? ...

How can I strip all html using a preg_replace ?

strip_tags only catches tags that have a beginning and end tag. With the strings I'm working with it's causing issues and I need to removed all HTML tags. ...