Irate Posted June 19, 2013 Share Posted June 19, 2013 So, I'm trying to implement a placeholder system on my forum, with a rather special syntax (I couldn't come up with something else, rather). Basically, they're supposed to look like this: {{t12345}} // link to an URL starting with t (for topics) {{t12345,12345}} // link to an URL starting with t but also include a fragment identifier for the exact post {{u12345}} // link to an URL starting with u (for users) {{homepage}} // any string of text can be inserted, I just want to interpret them differently, depending on the string {{h123}} // link to an URL starting with h (for html pages) So, I've written a Regex for this and want to replace it with according <a> tags... var regex = /\b(\{\{((t\d{1,5}|t\d{1,5}\,\d{1,6})|h\d{1,3}|DA|u\d{1,5}\}\}))/g; html = document.getElementsByTagName("body")[0].innerHTML; html.replace(regex, '<a href="$1">Generated link</a>'); That should do the basic user stuff, but for the homepage, HTML and topic URLs, I need an appending - to make the code work together with my forum's PHP pages. So, any ideas how I could change the URL according to the content on the $1 from the regex match? Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/279355-javascript-placeholders/ Share on other sites More sharing options...
Psycho Posted June 19, 2013 Share Posted June 19, 2013 (edited) Maybe I'm not understanding what you are doing. Why are you using regex to replace the placeholders? Just put those placeholders inside tags (DIV or SPAN) with an ID. Then just reference the ID. Are all of these on the same place in the page? If so, put them all within a parent container. Edited June 19, 2013 by Psycho Quote Link to comment https://forums.phpfreaks.com/topic/279355-javascript-placeholders/#findComment-1436851 Share on other sites More sharing options...
Irate Posted June 19, 2013 Author Share Posted June 19, 2013 Thing is, they're supposed to be dynamic and I want even illiterates to be able to use them without placing them inside divs or spans, so, for example... "This is Irate from {{homepage}} and recently, {{t12345,12345}} has caught my attention, so I want to thank {{u12345}} for creating this exceptional idea, which I have realized in {{h123}}." Am I being clear enough? :s Quote Link to comment https://forums.phpfreaks.com/topic/279355-javascript-placeholders/#findComment-1436860 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.