I'm trying to make it in java so that if I type a message that contains a link it automaticly formats it with html so it can be clickable on a webpage :P
However, the code i have written only turns the first "link" in my message to a link, not the others.
Can someone help me with this? I'm out of ideas...
My Code
// URL and Image handling
if (msg.contains("http://")) {
// If url is an image, embed it
if (msg.contains(".jpg") || msg.contains(".png") || msg.contains(".gif")) {
msg = msg.replace(linkz(msg, true), "<img src='" + linkz(msg, true) + "' class='embedded-image' />");
}
// Send link as link in <a> tag
msg = msg.replace(linkz(msg, true), "<a href='" + linkz(msg, true) + "' class='msg-link' target='_blank' title='" + linkz(msg, false) + "'>" + linkz(msg, false) + "</a>");
}
// Check string for links and return the link
public static String linkz(String msg, boolean http) {
String[] args = msg.split("http://");
String[] arg = args[1].split(" ");
if (http == true) {
return "http://" + arg[0];
}
return arg[0];
}