ianco Posted October 12, 2011 Share Posted October 12, 2011 Hi All I want to use wiki style bold (''') and italic ('') code form my form. So, it would be easy to use str_replace() for the opening tag but if you are using '''hello''' to bold the word hello, how can you differentiate the tags? I guess you would need some code to replace this alternatively but I haven't been able to find anything. I think Wikis are built from php so has anyone got any ideas? Many thanks Ian Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/ Share on other sites More sharing options...
requinix Posted October 12, 2011 Share Posted October 12, 2011 You use regular expressions instead. $bolded = preg_replace("/'''(.*?)'''/", '$1', $text); $italicized = preg_replace("/''(.*?)''/", '$1', $text); Bold first, otherwise you'll end up with titles looking like 'this'. (Or you could adjust the expressions.) Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1278706 Share on other sites More sharing options...
ianco Posted October 12, 2011 Author Share Posted October 12, 2011 thanks a lot. That's a big help. Ian Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1278720 Share on other sites More sharing options...
ianco Posted October 13, 2011 Author Share Posted October 13, 2011 If anyone wants any further info see a full list of wiki stuff http://bbpress.org/plugins/topic/mediawiki-wikitext-filter/ Ian Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1279108 Share on other sites More sharing options...
ianco Posted October 14, 2011 Author Share Posted October 14, 2011 HI again, I now want to reverse my preg_replace function $content = preg_replace("/(\\\'\\\')(.*?)(\\\'\\\')/", "<em>$2</em>", $content); This doesn't work: $content = preg_replace("/\<\e\m\>(.*?)\<\/\e\m\>/", "\'\'$1\'\'",$content); any ideas? Thanks Ian Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1279429 Share on other sites More sharing options...
requinix Posted October 14, 2011 Share Posted October 14, 2011 Question: why do you need to reverse it? Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1279454 Share on other sites More sharing options...
ianco Posted October 15, 2011 Author Share Posted October 15, 2011 Well, at the minute the data is stored in a database, I want to edit it in a textarea. Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1279643 Share on other sites More sharing options...
requinix Posted October 17, 2011 Share Posted October 17, 2011 Right. The best thing is to store two versions of the text: one with the wiki code and one converted to HTML. ... | wikitext | htmltext ----+------------+---------------------- | '''Bold''' | Bold One is for editing, which is converted to HTML when it changes, and the other is so that you don't have to convert the wiki markup every time the content is displayed. No reversing necessary. Quote Link to comment https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/#findComment-1279996 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.