I've been working on a little project, and I find myself in a position where I need a php function which can linkify URLs in my data, while enabling me to set some exceptions on links I don't want to linkify. Any idea of how to do this?
Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):
$ pecl -d php_suffix=5.6 install <package> $ pecl uninstall -r <package> $ pecl -d php_suffix=7.0 install <package> $ pecl uninstall -r <package> $ pecl -d php_suffix=7.1 install <package> $ pecl uninstall -r <package>
-d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with
pecl config-set. The
uninstall -r bit does not actually uninstall it (from the docs):
vagrant@homestead:~$ pecl help uninstall pecl uninstall [options] [channel/]<package> ... Uninstalls one or more PEAR packages. More than one package may be specified at once. Prefix with channel name to uninstall from a channel not in your default channel (pecl.php.net) Options: ... -r, --register-only do not remove files, only register the packages as not installed ...
The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).
It turned out to be a simple solution!
However you won't be able to do the
not visited differentiation.
TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1); noteView.setText("http://www.blablaasd.com/"); noteView.setLinkTextColor(Color.red); //for example Linkify.addLinks(noteView, Linkify.ALL);
My attempts to catch visited states:
res/ create folder
color and create
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_window_focused="true" android:color="#00ff00"> </item> <item android:state_window_focused="true" android:color="#00ff00"> </item> <item android:color="#FF00ff"/> </selector>
I have tried my best to catch visited states. I tried all the states a selector can take.
I might have missed In case you found out, share (:
ALTERNATE SOLUTION (works only for html links)
Set the font Color programatically
Drawback (Be carefull for this point)
You will have to catch whether it was visited or not (this is doable)
This means that you are not overriding the visited links functionality.
TextView contactWeb1 = (TextView) findViewById(R.id.contactWeb1); String desc = "<font color="red"><a href='http://www.mysite.com/'>Visit my site</a></font>"; contactWeb1.setText(Html.fromHtml(desc)); contactWeb1.setMovementMethod(LinkMovementMethod.getInstance());
Never used any of those, but they look interesting..
Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..
Look like you need to put
http:// at the beginning of that URL. Without the protocol specifier Android appears to assume "content://" is the intended url type.
I have an open source project on GitHub: LinkifyURL which you may want to consider. It has a function:
linkify()which plucks URLs from text and converts them to links. Note that this is not a trivial task to do correctly! (See: The Problem With URLs - ands be sure to read the thread of comments to grasp all the things that can go wrong.)
If you really need to NOT linkify specific domains (i.e. vimeo and youtube), here is a modified PHP function
linkify_filtered(in the form of a working test script) that does what you need:
linkify()in action here: URL Linkification (HTTP/FTP).
Also, John Gruber has a pretty good regex to do linkification. See: An Improved Liberal, Accurate Regex Pattern for Matching URLs. However, his regex suffers catastrophic backtracking under certain circumstances. (I've written to him about this, but he has yet to respond.)
Hope this helps! :)