Royalmike Posted June 18, 2010 Share Posted June 18, 2010 Not sure if anyone is a familiar with CKEditor, but it's an HTML WSYIWYG editor that can be added to a website to modify content. With CKEditor you can do a lot of different things along with making links. When you click the link button, you have a few options, http://, ftp://, https://, news://, and other(for internal links) I'm trying to develop a way without trying to edit the CKEditor javascript, to make it so when the user chooses other(meaning http://, ftp://, https://, or news:// doesn't exist) that it adds a php variable to the beginning of the link. Ex: <a href="test1">Test Page</a> reformed to <a href="<?php echo $baseDirectory; ?>test1>Test Page</a> I've accomplished this by doing: $pattern = "/href=/"; $test= preg_replace($pattern, '<a href="<?php echo $baseDirectory; ?>', $test); $test = str_replace('<a href="<?php echo $baseDirectory; ?>\"', '<a href="<?php echo $baseDirectory; ?>', $test); $test = str_replace('\"', '"', $test); But when I choose another option other than other it adds it to it as well so: <a href="http://google.com">Google</a> gets reformed to <a href=<?php echo $baseDirectory; ?>http://google.com</a> I need it so it only adds it to the other option, not the http://, ftp://, https://, news:// options. Link to comment https://forums.phpfreaks.com/topic/205222-adding-on-to-a-link-from-wysiwyg/ Share on other sites More sharing options...
kratsg Posted June 19, 2010 Share Posted June 19, 2010 You're almost there! You just need to get your pattern to insert when it ISN'T one of those options.. IE: $pattern = "/href=/"; To $pattern = "/href=[^(http|ftp|https|news|)]/"; The parentheses will actually return you the value that they chose (which you don't need to worry about). The "^" character is a "not" character, meaning when href=[NOT ....], then insert baselink. Does that make sense? Link to comment https://forums.phpfreaks.com/topic/205222-adding-on-to-a-link-from-wysiwyg/#findComment-1074282 Share on other sites More sharing options...
Royalmike Posted June 19, 2010 Author Share Posted June 19, 2010 It didn't work. It still adds it to the http, etc. I even tried being more specific with the http, ftp, https, and news by adding the "://" and changing the beginning and ending delimiters to "#" instead(since the slash delimiters would have caused problems with the "://"). I understand that "^" and it would make sense that would be exactly what I want... This is what I tried and explained above. $pattern = "#<a href=[^(http://|ftp://|https://|news://|)]#"; $test= preg_replace($pattern, '<a href="<?php echo $baseDirectory; ?>', $test); $test = str_replace('<a href="<?php echo $baseDirectory; ?>"', '<a href="<?php echo $baseDirectory; ?>', $test); $test = str_replace('\"', '"', $test); Link to comment https://forums.phpfreaks.com/topic/205222-adding-on-to-a-link-from-wysiwyg/#findComment-1074288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.