Jump to content

trying to copy wiki code


ianco

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/248988-trying-to-copy-wiki-code/
Share on other sites

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.)

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.