Take for example the following regex match.
preg_match('!^publisher/([A-Za-z0-9\-\_]+)/([0-9]+)/([0-9]{4})-(january|february|march|april|may|june|july|august|september|october|november|december):([0-9]{1,2})-([0-9]{1,2})/([A-Za-z0-9\-\_]+)/([0-9]+)(/page-[0-9]+)?$!', 'publisher/news/1/2010-march:03-23/test_title/1/page-1', $matches);
p...
In a text, I would like to replace all occurrences of $word by [$word]($word) (to create a link in Markdown), but only if it is not already in a link. Example:
[$word homepage](http://w00tw00t.org)
should not become
[[$word]($word) homepage](http://w00tw00t.org).
Thus, I need to check whether $word is somewhere between [ and ] and on...
Let assume that $body is equal to
something
that
does
not
interest
me
<!-- start -->
some
html
code
<!-- end -->
something
that
does
not
interest
me
If I use
$body=preg_replace("(.*)<!-- start -->(.*)<!-- end -->(.*)","$2",$body);
I obtain:
Warning: preg_replace() [function.preg-replace]: Unknown modifier '<'
How have I t...
I have a bunch of files that were named in a somewhat standard format. The standard form is basically this:
[integer]_word1_word2_word3_ ... _wordn where a word could really be anything, but all words are separated by an underscore.
There is really only 3 things I want to do to the text:
1.) I want to modify the integer, which is al...
I am trying to take a string of text like so:
$string = "This (1) is (2) my (3) example (4) text";
In every instance where there is a positive integer inside of parentheses, I'd like to replace that with simply the integer itself.
The code I'm using now is:
$result = preg_replace("\((\d+)\)", "$0", $string);
But I keep getting a ...
Hi All
I don't usually use regular expressions, hence my question. I need a regex to match the following:
'{any-string}'.
Any assistance appreciated.
...
Hi there. I am using preg_replace to add a link to keywords if they are found within a long HTML string. I don't want to add a link if the keyword is found within h1 tags or strong tags.
The below regex nearly works and basically says (I think): If the keyword is not immediately wrapped by either a h1 tag or a strong tag then replace wi...
Hy i have to test if a string begins with 00 or with +
Say i have the string 0090 or +41 if the string begins with 0090 return true, elseif string begins with +90 replace the + with 00 else return false
The last two digits can be from 0-9
How do i do that in php?
I hope i could explain my question clear?
...
This is what i want to do:
$line = 'blabla translate("test") blabla';
$line = preg_replace("/(.*?)translate\((.*?)\)(.*?)/","$1".translate("$2")."$3",$line);
So the result should be that translate("test") is replaced with the translation of "test".
The problem is that translate("$2") passes the string "$2" to the translate function. ...
I have a paragraph of text and i want to replace some words using PHP (preg_replace). Here's a sample piece of text:
This lesson addresses rhyming [one]words and ways[/one] that students may learn to identify these words. Topics include learning that rhyming words sound alike and these sounds all come from the [two]ending of the words[/...
Masters of regular expressions, please help!
See this string:
$string = "http://www.url.com/?fieldA=123&fieldB=456&fieldC=789";
Assuming "fieldB" always has a positive non-decimal numerical value (but not necessarily three digits long), what preg_replace command do I need to remove it completely, such that the string will the...
UPDATE: As it turns out, the below is caused by a caching issue on my production server. Thanks to everybody who contributed thoughtful answers.
I have a simple function on a php page that takes a url such as:
http://myurl.com/mypage.html?param1=value1
and converts it to:
http://myurl.com/searchpage.html?param1=value1
All it does it...
Hello, I have this snippet
while($row = mysql_fetch_array($result)){
$search = '' . $row['searchquery'];
echo '<a href="http://www.example.com/' . preg_replace( array('/[^\s\w]/','/\s/'),array('','+'),$search) . '+/">' ...
but if someone types in äöü, it doesnt show the letters - with rawurlencode thats possible, but I want to remov...
Hey,
I'm using the code below to highlight some keywords in a text:
$message = str_ireplace($words,'<span class="hightlighted_text">'.$words.'</span>',$message);
The text may contain some html tags, for example , etc..
How can I highlight "normal" text, except the text between the html tags? Because when users search for "img" the ...
Hello,
I have a news site containing an archive with more than 1 million news.
I created a word definitions database with about 3000 entries, consisting of word-definition pairs.
What I want to do is adding a definition next to every occurence of these words in the news.
I cant make a static change as I can add a new keyword everyday, ...
I found a function online for turning a url within a string into a clickable link. However, when the url contains a hashtag it doesn't work. eg. http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759
Here's the part of the function concerned:
$ret = preg_replace(
"#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#",
"\\1<a ...
This question is related to a similar case, namely http://stackoverflow.com/questions/2488950/removing-inline-styles-using-php
The solution there does not remove i.e: <font face="Tahoma" size="4">
But let's say I have a mixed bag of inline styles and properties, like this:
<ul style="padding: 5px; margin: 5px;">
<li style="padding...
I have a requirement to place text between brackets using jQuery; the content will be updated once an action occurs e.g. search.
The structure is: -
<h2>Placeholder Text Placeholder Text Placeholder Text ()</h2>
...
mmmh guys, i really hope my english is good enaught to explain what i need.
Lets take this example (that is just an example!) of code:
class Something(){
public function Lower($string){
return strtolower($string);
}
}
class Foo{
public $something;
public $reg;
public $string;
public function __construct(...
I'm trying to strip content titles out of the middle of text strings. Could I use regex to strip everything out of this string except for the title (in italics) in these strings? Or is there a better way?
Joe User wrote a blog post called
The 10 Best Regex Expressions in the category Regex.
Jane User wrote a blog post called
...