Your Ad Here

Thursday, February 26, 2009

find and replace string within a string

Here's a fun one. I've got a CMS, and for editing purposes, I'm building in a script manager. It's like this -- the WYSIWYG editor (InnovaStudio) I'm using in the CMS doesn't like plug-in javascript, so I'm going to allow the user to maintain a little script library elsewhere in the management for their google tracking codes or whatever, and have a dropdown on the page editor when they want to plug one in. I've built a version of the inserter already and it works well. The problem is the JavaScript, so I'm going to let the inserter plug in a placeholder for the script, then when they submit changes to the page it will convert, for instance "<<<>>>google.script<<<>>>" into the chunk of JavaScript that needs to actually be written to the page, and write it into the page. Now, if they pull up that page again, it needs to find that script before it's loaded into the WYSIWYG and convert it back to a placeholder so it doesn't get screwed up by the WYSIWYG.

Clear as mud, right?

Well here's the catch. In the following code, I just run through my database table of scripts to see if any match (they are all saved with identical "") - $process_length_start);
$scriptend = (strpos($currentcode, "") + $process_length_end);
$scriptcode=substr($currentcode, $scriptstart, ($scriptend - $scriptstart));
$currentcode=ereg_replace($scriptcode,"<<<>>>".$scriptrow['name']."<<<>>>",$currentcode);

}
---------
Any ideas?

Read More...
Your Ad Here

No comments: