We help IT Professionals succeed at work.
Get Started

Hyperlinks not formatting correctly using TinyMCE

LearningPHPMySQL
on
528 Views
Last Modified: 2013-12-13
Hi, I am trying to insert hyperlinks on my pages using TinyMCE.

I have tried both using the toolbar option and adding the link details in there, and also manually, but each time it is outputting wrong.

instead of the link being http://www.numyspace.co.uk/~unn_r031923/Testing/login-OOtest.php

it is being outputted like this.

http://www.numyspace.co.uk/~unn_r031923/Testing/\"login-OOtest.php\"

I have searched the help files and found this below. The question is, how could i adapt this script into my index.php code?



HTML output include lots of \" like <a href=\"mylink.htm\">link</a>?

This is probably because you are using PHP and it has a feature that's called magic quotes that is enabled by default. You can read more about this in the PHP documentation.

A quick way to clean up magic quotes is to use this (taken from the PHP manual):

if (get_magic_quotes_gpc()) {
    function stripslashes_deep($value)
    {
        $value = is_array($value) ?
                    array_map('stripslashes_deep', $value) :
                    stripslashes($value);

        return $value;
    }

    $_POST = array_map('stripslashes_deep', $_POST);
    $_GET = array_map('stripslashes_deep', $_GET);
    $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
    $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}


index.php
-----------------
<?php
include("header.html");
 
// Get the page name from the query string
$page = $_GET['page'] .'.txt';
if (!$_GET['page']) {
 
  echo("<h1>Page name not specified</h1>\n");
  include("../footer.html");
  exit;
}
 
// This step is checking to see if I have posted. 
// If I have posted the page contents, it opens up the 
// filename indicated by the query string, writes it out, 
// closes the file, shows  the new contents of the file, 
// sources the footer and quits.
if (isset($_POST['page'])) {
  $handle = fopen("../pages/$page", 'w');
  fwrite($handle, $_POST['page']);
  fclose($handle);
  include("../footer.html");
  exit;
}
 
// If I have specified a page that exists, read it into the 
// $text variable. If the page doesn't exist, 
// mention that I am creating a new one at the top of the page, 
// and set $text to an empty paragraph (<p></p>). 
if (file_exists("../pages/$page")) {
  $FILE = fopen("../pages/$page", "rt");
  while (!feof($FILE)) {
    $text .= fgets($FILE);
  }
  fclose($FILE);
} else {
   echo("<h1>New Page: $page</h1>\n");
  $text = "<p></p>";
}
 
 
// JavaScript is usually loaded in the <head> section of a page. 
// But since the <head> section is // in the shared header.html, 
// I don't want to load this up for every page, just the editing page. 
// Because of this, i am putting it in the <body> section. 
// The "init" section is where all the // options are for the editor. 
// "mode: textareas" means that all text areas on the page will become
// TinyMCE WYSIWYG texareas. 
echo <<< EOM
<script language="javascript" type="text/javascript" src="/~unn_r031923/Testing/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
 
// General options
mode : "textareas",
theme : "advanced",
 
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
 
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
 
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
 
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|",
 
theme_advanced_buttons4 : "moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,|,insertfile,insertimage",
 
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_resizing : true,
 
// Example content CSS (should be your site CSS)
content_css : "Testing/project.css",
 
// Drop lists for link/image/media/template dialogs
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
 
 
});
</script>
EOM;
 
// Here I create the form, the textarea and the "Save" button. 
// The "htmlspecialchars($text)" call reads the $text variable,
// and replaces all the special characters with the 
// HTML special character codes. This is so the HTML in 
// the file doesn't clash with the HTML on this page.
// The output of this function then gets passed to the textarea.
// When the "Save" is clicked, it calls the same page again 
// with the same query string, but this time there is some posted
// information containing the editing i did. 
// This is sent to the second section of code at the top
// of this page to be saved to a file.
 
$this_page = $_SERVER['PHP_SELF'];
$query_string = $_SERVER['QUERY_STRING'];
echo("<form method=\"post\" action=\"$this_page?$query_string\">\n");
echo("<textarea id=\"page\" name=\"page\" rows='25' cols='80'>\n");
echo(htmlspecialchars($text));
echo("</textarea>\n");
echo("<input type=\"submit\" value=\"Save\"/>\n");
echo("</form>\n");
 
// load the footer and close out the PHP script.
include("footer.html");
 
?>

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE