I have a simple commenting system here...
http://affbuzz.com/comments/7299a55137def55917a5dc6c4fe0f261af8a4217
...and people can submit hyperlinks inside the plain text field. When I display these records back from the database and into the web page, what RegExp in PHP can I use to convert these links into HTML-type anchor links?
Bonu...
Here's my Codeigniter function:
function edit_phone($phone)
{
if (preg_match('/^\(?[0-9]{3}\)?[-. ]?[0-9]{3}[-. ]?[0-9]{4}$/', $phone))
{
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1-$2-$3", $phone);
}
else
{
$this->CI->validation->set_m...
As hard as I try, PREG and I don't get along, so, I am hoping one of you PHP gurus can help out ..
I have some HTML source code coming in to a PHP script, and I need specific items stripped out/removed from the source code.
First, if this comes in as part of HTML (could be multiple instances):
<SPAN class=placeholder title="" jQuery12...
I have some text, something like this:
Paragraphs of text
(SOME KNOWN TEXT)Unknown Text(SOME OTHER KNOWN TEXT)
Some additional paragraphs of text
What I want is to keep the Unknown Text, but get rid of the (SOME KNOWN TEXT) and (SOME OTHER KNOWN TEXT).
I think the preg_replace will give me what I want, but I need the regular expressi...
In the documentation for preg_replace is says you can use indexed arrays to replace multiple strings. I would like to do this with associative arrays, but it seems to not work.
Does anyone know if this indeed does not work?
...
Hello!
I have a string like "Welcome to McDonalds®: I'm loving it™"... I want to get rid of ":", "'", ® and ™ symbols, so I do the following:
$string = "Welcome to McDonalds®: I'm loving it™";
$string = preg_replace('/[^a-zA-Z0-9 -]/', '', $string);
BUT on the output I receive:
"Welcome to McDonaldsreg Im loving ittrade"... so preg...
I'm trying to find some certain blocks in my data file and replace something inside of them. After that put the whole thing (with replaced data) into a new file. My code at the moment looks like this:
$content = file_get_contents('file.ext', true);
//find certain pattern blocks first
preg_match_all('/regexp/su', $content, $matches);
f...
I use PHP.
I'm working on a way to automatically put together all my CSS files into one. I automatically load the CSS-files and then saves them to a larger one, for upload.
In my local installation I have some @import lines that needs to be removed.
It looks like this:
@import url('css/reset.css');
@import url('css/grid.css');
@impor...
LS,
I'm using the following code to add <span> tags behind <a> tags.
$html = preg_replace("~<a.*?href=\"$url\".*?>.*?</a>~i", "$0<span>test</span>", $html);
The code is working fine for regular links (ie. http://www.google.com/), but it will not perform a replace when the contents of $url are $link$/3/.
This is example code to show ...
There are heaps of Qs about this on this forum and on the web in general.
But I don't just get it.
Here is my code:
function updateGuideKeywords($dal)
{
$pattern = "/[^a-zA-Z-êàé]/";
$keywords = preg_replace($pattern, '', $_POST['keywords']);
echo json_encode($keywords);
}
Now, the input is Prêt-à-porter, and the output i...
I have some code with the a structure similar to this
function bbcode($Text)
{ //$Text = preg_replace("/\[video\](.+?)\[\/video\]/",embed_video($1), $Text);
return $Text;}
function embed_video($url){
if (preg_match("/http:\/\/www.youtube.com\/watch\?v=([0-9a-zA-Z-_]*)(.*)/i", $url, $matches)) {
return ...
I'm using php's preg_split to split up a string based on semi-colons, but I need it to only split on non-escaped semi-colons.
<?
$str = "abc;def\\;abc;def";
$arr = preg_split("/;/", $str);
print_r($arr);
?>
Produces:
Array
(
[0] => abc
[1] => def\
[2] => abc
[3] => def
)
When I want it to produce:
Array
(
[0] =...
I have a preg_replace taking out a part of a string it shouldn't be removing.
It should be looking for: images_client/39/structure/party-2/
And replacing it with: images_client/39/structure/xxx/
It does do that, but it's also removing the images/ part of it just before apple_logo.jpg
<?php
echo '<br>-------- preg_replace on a css...
I have a block of code that will take a block of text like the following:
Sample text sample text http://www.google.com sample text
Using the preg_replace_callback method and the following regular expression:
preg_replace_callback('/http:\/\/([,\%\w.\-_\/\?\=\+\&\~\#\$]+)/',
create_function(
'$matches',
'$url =...
hello guys - moving a lot more of my old php functions to jquery alternatives. I'm a bit stuck on creating a decent preg_match function.
Is there an easy way to make strings url safe & seo'd?
php;
function superClean($str){
$str = strtolower($str);
$str = str_replace(" ", "-", $str);
$str = preg_replace('/[^a-z0-9_]/i', '-', $str);
$...
$line = "Hello World";
$line= preg_replace("/Hello/", $replacement, $line); - Works!
$find = "Hello";
$line= preg_replace("/$find/", $replacement, $line); - Wont replace anything!
$string = "Hello";
$find = "/".$string."/";
$line= preg_replace($find, $replacement, $line); - Wont replace anything!
How can I use a variable in to tell ...
I've got a string :
$source = '&
<script type="text/javascript">&</script>
&
<script type="text/javascript">&</script>
&';
The desired result is :
&
<script type="text/javascript">&</script>
&
<script type="text/javascript">&</script>
&
I try with :
echo preg_replace("#&(?!amp;)(?!<\/script>)(?![^<]script.*?>)#i",
...
I need to replace multiple instances of a certain string (question mark) with strings from an array. e.g. if the string I wish to replace appears 3 times and my array has a length of 3, the first one would be replaced by the first item in the array, the second by the second etc etc.
You may recongise it's quite similar to the way prepar...
Example
Input = 1.1.0.1
Expected output = 1.101
...
I need a little help here. This code correctly displays every format I enter--except when it's xxx.xxx.xxxx
It keeps the periods in! How do I filter out periods too?
preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "$1-$2-$3", $phone_enter)
...