Newbie here :)
First my AS2 code:
txt.html=true;
txt.htmlText="This is an example: www.sample.com is not www.othersample.com";
var sampleText:String=findUrl(txt.text);
trace(sampleText);
function findUrl(str){
var rawURL:Array = new Array();
rawURL = str.split(' ');
for(var i=0; i<rawURL.length; i++) {
if(rawURL[i].indexOf("http://") != -1 or rawURL[i].indexOf("www.") != -1) {
return (str.replace(rawURL[i], "<a href='"+rawURL[i]+"' target='_blank'><u><font color='#666666'>"+rawURL[i]+"</font></u></a>"));
}
}
}
Output:
This is an example: <a href='www.sample.com' target='_blank'><u><font color='#666666'>www.sample.com</font></u></a> is not www.othersample.com
First question is why my flash function always replace only first url?
What I'm trying to do is send string from flash input textfield by PHP to mySQL table. Then, when flash will load it again all urls in my flash textfield will be clickable.
Of course I can use preg_replace in PHP:
$comments = $_POST['comments'];
$comments = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2", $comments);
$comments = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i", "<u><A TARGET=\"_blank\" HREF=\"$1\"><font color=\"#666666\">$1</font></A></u>", $comments);
but the problem is that this string is editable in flash, so when I send it (edited) back to PHP, PHP overwriting links and make them unreadable for flash (example):
<u><a target="_blank" href="<u><a target="_blank" href="http://asdasd.asdasd.pl"><font color="#666666">http://asdasd.asdasd.pl</font></a></u>"><font color="#666666"><u><a target="_blank" href="http://asdasd.asdasd.pl"><font color="#666666">http://asdasd.asdasd.pl</font></a></u></font></a></u>
I can also use some PHP function which will check whether sended data from flash already contains clickable url's, but if I need add another link in edited string, preg_replace not fire then...
Is there any way to do what I need?
Thanks in advance, Artur.