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
https://forums.phpfreaks.com/topic/86538-remove-urls/#findComment-442214
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
https://forums.phpfreaks.com/topic/86538-remove-urls/#findComment-443045
Share on other sites

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

 

To separate and comment the different parts.

 

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?

 

Unicode Character Properties.

Link to comment
https://forums.phpfreaks.com/topic/86538-remove-urls/#findComment-445169
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
https://forums.phpfreaks.com/topic/86538-remove-urls/#findComment-447871
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.