Possible Duplicate:
Regex to change format of all img src attributes
Hi,
I want to replace the image path in my content db field.
I have the following
preg_replace("/src='(?:[^'\/]*\/)*([^']+)'/g","src='newPath/$2'",$content);
which is working fine for
src="/path/path/image.jpg"
BUT fails ON
src="http://www.mydomain....
I am trying to replace accented characters with the normal replacements. Below is what I am currently doing.
$string = "Éric Cantona";
$strict = strtolower($string);
echo "After Lower: ".$strict;
$patterns[0] = '/[á|â|à|å|ä]/';
$patterns[1] = '/[ð|é|ê|è|ë]/';
$patterns[2] = '/[í|î|ì|ï]/';
$patterns[3] = '/[...
What I want
If the URL in the string contains a .jpg at the end of the URL (not the string) then it should make an image from it with preg_replace else make a normal link.
so for example:
If I have http://www.example.com/images/photo.jpg then it should replace with:
<img src="http://www.example.com/images/photo.jpg" alt="http://ww...
Could you tell how to replace string by preg-replace (need regular expression):
/user/{parent_id}/{action}/step/1
At the equivalent values of an array:
array('parent_id'=>32, 'action'=>'some');
To make:
/user/32/some/step/1
Addition
This is a typical problem, so I probably will not know what the names of variables come
...
I need to add a string before CSS elements with Javascript code. An example of the original code:
h1 {
background: red;
}
.class #id {
color: black;
}
I want Javascript to filter it like this:
.myclass h1 {
background: red;
}
.myclass .class #id {
color: black;
}
Let's say the CSS-code is a Javascript string called st...
<hr>I want to remove this text.<embed src="stuffinhere.html"/>
I tried using regex but nothing works.
Thanks in advance.
P.S. I tried this: $str = preg_replace('#(<hr>).*?(<embed)#', '$1$2', $str)
...
Hello, I'm new to regular expressions, but I'm trying to learn about it. I want to remove the tag of a html text, and let only the inner text. Something like that:
Original: Lorem ipsum <a href="http://www.google.es">Google</a> Lorem ipsum <a href="http://www.bing.com">Bing</a>
Result: Lorem ipsum Google Lorem ipsum ...
I am trying to do a replace within a string in PHP. How do you delete the part that is only in the group in PHP?
<font.+?(size.+?.)>
I want to remove size=x where ever it in. The problem is I cannot get the
$text = preg_replace("<font.+?(size.+?.)>","",$text);
function to work.
Example source of this
<font style="background...
Here is what I have
<img src="http://some.site.com/v/b/image-name/_thumb_100x100.jpg">
I'm trying to modify the src by replacing the size to _thumb_200x200.jpg
i tried preg_replace() but nothing .
...
I'm writing some autosuggest functionality which suggests page names that relate to the terms entered in the search box on our website.
For example typing in "rubbish" would suggest "Rubbish & Recycling", "Rubbish Collection Centres" etc.
I am running into a problem that some of our page names include macrons - specifically the macron ...
I need to do a preg_replace on all of the PHP tags in a string, as well as any characters sitting between the PHP tags.
Eg, if the file contents was:
Hey there!
<?php some_stuff() ?>
Woohoo!
All that should be left is:
Hey there!
Woohoo!
Here's my code:
$file_contents = file_get_contents('somefilename.php');
$regex = '#([<?php](....
Hello, I'm using the PDO class but I'm triying to remove all chars except...:
function cleaner($str){
return preg_replace('/[^a-zA-Z0-9éàêïòé\,\.\']/',' ',trim($str));
}
As you can see, it's a simple function, but it removes all chars éàêïòé
example: cleaner('$#$<<>-//La souris a été mangée par le chat ') //returns
La souris a...
Hi. I am working on validating username, pass and email with php. I need to be sure I get it right so nobody can bypass the login page.
This is the values:
$email=$_POST['email'];
$username=$_POST['uname'];
$passwd=$_POST['pass'];
$passwd2=$_POST['passcopy'];
So far I have email validation:
if(!(preg_match("/^[\.A-z0-9_\-\+]+[@][A-...
I use regex to create html tags in plain text. like this
loop
$SearchArray[] = "/\b(".preg_quote($user['name'], "/").")\b/i";
$ReplaceArray[] = '<a href="'.$user['url'].'">$1</a>';
-
$str = preg_replace($SearchArray, $ReplaceArray, $str);
I'm looking for a way to not match $user['name'] in a tag.
...
In follow-up to my previous question, I want to replace every instance of an ALL-CAPS* word with a link of the following format:
dictionary.com/browse/<TERM>
The preg_replace call I am using is this:
$content = preg_replace('#[A-Z][A-Z]+#', '<a href="//dictionary.com/browse/$1">$1</a>', $content);
Using http://gskinner.com/RegExr, ...
Hello my second family, :)
I'm just wondering how to apply several rules for a preg_replace without executing them in the first run. Its a bit complicated let me explain based on an example.
Input:
$string = 'The quick brown fox jumps over the lazy freaky dog';
Rules:
Replace a, i, o with u (if not at the beginning of a word & ...
I need to turn names that are always in lower case into uppercase.
e.g. john johnsson -> John Johnsson
but also:
jonny-bart johnsson -> Jonny-Bart Johnsson
How do I accomplish this using PHP?
...
How do i change any of the following to just numbers
1-(999)-999-9999
1-999-999-9999
1-999-9999999
1(999)-999-9999
1(999)999-9999
i want the final product to be 19999999999
...
I'm looking to do something like get the opposite match from this line:
$input = "21.asdf*234true;asdf0--11"
$_BOOL_ ="/(true|false)/i";
$output = preg_replace($_BOOL_, '', $input);
//Result: "21.asdf*234;asdf0--11"
//Desired result: "true"
Which ofcourse in php 5.3 is
$output = preg_filter($_BOOL_, '', $input);
But I'm on 5.2, and...
I am having a little trouble converting the below regular expressions to the updated preg_replace function.
$string = ereg_replace("(a:http://)([a-zA-Z 0-9 \#\&\;\@\:\/\.\_\-]*)\|([a-zA-ZÄÖÜäöü 0-9 \#\&\;\@\:\/\.\_\-]*)","<a href=\"http://\\2\">\\3</a>",$string);
$string = ereg_replace("(a:http://)([a-zA-Z 0-9 \#\&\;\@\:\/\.\_...