Jump to content

Remove URL's


The Little Guy

Recommended Posts

http

https

ftp

www

 

so... if I have one or more of the following:

 

visit: https://google.com and WIN!

visit: https://www.google.com and WIN!

visit: http://google.com and WIN!

visit: http://www.google.com and WIN!

visit: www.google.com and WIN!

visit: ftp://www.google.com and WIN!

visit: ftp://google.com and WIN!

 

or any other common urls, it would then format it like this:

 

visit: [ URL REMOVED ] and WIN!

Link to comment
Share on other sites

Effigy your regex will match:

www.lalallookiamnotareallink

http://again (look even SMF thinks these are links)

 

All urls have at least 1 '.' in them so I'd say:

~(??:(?:https?|ftp)://)|www\.)(?:\S+\.\S+)(?<!\p{P})~

 

I also don't see why you are using the x modifier because \S will not match white space anyways.

 

I couldn't figure out the meaning of the P unicode grapheme, could you a provide a link to a listing of these, or just tell what it is?

Link to comment
Share on other sites

I've been to this page but it does not specify what punctuation marks it matches exactly, unicode supports many many languages, and in different languages punctuation means different things and there exists punctuation marks outside the realm of english punctuation marks.

Link to comment
Share on other sites

There's a basic showing here.

 

And this will show you as much as you want:

 

<meta charset="utf-8"/>
<pre>
<?php
### Up the range as much as you want.
### Unicode 5.0.0 contains 1,114,112 characters.
foreach (range(0, 127) as $code_point) {
	$utf = code2utf($code_point);
	if (preg_match('/\p{P}/u', $utf)) {
		printf('[%09s]: ', number_format($code_point));
		echo $utf, '<br/>';
	}
}

### Borrowed from http://us3.php.net/manual/en/function.utf8-encode.php#58461
function code2utf($num) {
   if($num<128)return chr($num);
   if($num<2048)return chr(($num>>6)+192).chr(($num&63)+128);
   if($num<65536)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
   if($num<2097152)return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
   return '';
}
?>
</pre>

 

For example:

 

[000000033]: !

[000000034]: "

[000000035]: #

[000000037]: %

[000000038]: &

[000000039]: '

[000000040]: (

[000000041]: )

[000000042]: *

[000000044]: ,

[000000045]: -

[000000046]: .

[000000047]: /

[000000058]: :

[000000059]: ;

[000000063]: ?

[000000064]: @

[000000091]: [

[000000092]: \

[000000093]: ]

[000000095]: _

[000000123]: {

[000000125]: }

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.