Modify all Wordpress posts for syntax highlighter

Nov1
  • Share/Bookmark

Difficulty: ★★★☆☆
I installed a new syntax highlighter for this blog.
The thing is, with syntax highlighters that they all use their own prefix.
For example my previous one used the tags:

<pre lang="php">echo "this"</pre>

My new highlighter plugin uses this:

[code lang="php"]echo "this"[/code

Fine for me to start using this, but how can I modify all my 500 blog posts to the new syntax?
Regex is the answer! What I did is, I first made a database export (sql) from all my wordpress posts in phpMyAdmin.
I saved the sql query to my harddisk, and then opened it with a code editor (PSPad is good for regex).
I replaced all:

//FIND
<pre lang="(.+?)">(.+?)</pre>
//REPLACE
[code lang="$1"]$2[/code

Save the new query on your harddisk, which contains Wordpress post in the new format.
In phpMyAdmin I emptied/truncated the "wp_post", table, so none of the posts where there.
Then I imported the new query, and voila!
My new syntax highlighter is working!



Leave a comment