var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]");
var mpos1 = input.indexOf("[[Image");
for(i=mpos1;i<=input.length;i++)
{
var mpos2 = input.indexOf(":");
}
var istr1 = input.substring(mpos1, mpos2);
var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]");
var mpos1 = input.indexOf("[[Image");
for(i=mpos1;i<=input.length;i++)
{
var mpos2 = input.indexOf(":");
}
var istr1 = input.substring(mpos1, mpos2);
Hm. I'd do:Code:var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]"), text = input.match(/[[Image:([^\|]+)|([^\]]+)]]/), url = text[0]; text = text[1];
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Code:<script type= "text/javascript"> var input = window.prompt("Enter Text Here","see this: [[Image:wiki-en.png|Wikipedia]]"); var mpos1 = input.indexOf("[[Image:"); var init = "[[Image:" var colon = init.lastIndexOf(":") for(i=mpos1;i<=input.length;i++) { var mpos2 = input.indexOf("|"); } for(i=mpos1;i<=input.length;i++) { var mpos3 = input.indexOf("]]"); } var istr0 = input.substring(0, mpos1) var istr1 = input.substring(mpos1, colon); var websi = input.substring(colon, mpos2) var istr2 = input.substring(mpos2, mpos2+1); var istr3 = input.substring(mpos2+1, mpos3); var istr4 = input.substring(mpos3, mpos3+2); var istr5 = input.substring(mpos3+2, input.length); if(istr1.indexOf("[[Image:") != -1) { var ipos1 = istr1.replace("[[Image:", '<img src="http://en.wikipedia.org/wiki/Image:'); } if(istr2.indexOf("|") != -1) { var ipos2 = istr2.replace("|", '" alt="'); } if(istr4.indexOf("]]") != -1) { var ipos3 = istr4.replace("]]", '</img>"'); } var newimage = (istr0+ipos1+websi+ipos2+istr3+ipos3+istr5); document.write(newimage); ---- when I output this, it doesn't output ipos1. It doesn't even transform it. I'm thinkin it has to do with the fact that i can't find mpos2.
This is really very ugly. Regex is much nicer.Code:function unWikifyImages(str) { return str.replace(/\[\[Image:([^\|]+)\|([^\|]+)\]\]/, '<img src="$1" alt="$2">'); }
Last edited by Twey; 10-08-2006 at 11:56 AM.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks