Page 1 sur 1

erreur introuvable pour moi.

Posté : 17 août 2005, 14:06
par NightAngel
J'ai fais ce petit script et il me retourne cette erreur

Parse error: parse error, unexpected T_FUNCTION in /var/www/free.fr/b/d/site/test/testbbcode_html.php on line 8

mon script :
<?php

include 'inc_cg_filter.php'

function verifsubmit()
{
	var ok_return = true;
	var html_bbcode = true;
	var bbcode_html = true;
	var html = window.document.formulaire.texte.value;
	var bbcode = window.document.formulaire.texte.value;

    // test si un des champs est rempli
	if (html == '')
	    var html_bbcode = false;
	if (bbcode == '')
	    var bbcode_html = false;

    // test si les 2 champs sont vide
	if (html_bbcode==false)
		if (bbcode_html==false)
		{
			alert('Vous n\'avez renseigné aucun des champs');
			var ok_return = false;
		}
	// test si les 2 champs sont plein
    if (html_bbcode==true)
		if (bbcode_html==true)
		{
			alert('Vous avez renseigné tout les champs');
			var ok_return = false;
		}
	
	if (html_bbcode==true) 
		$convert_html_bbcode=function bbcode_to_html($html);
		else if (bbcode_html==true)
		         $convert_bbcode_html=function bbcode_to_html($bbcode);
		       
    return ok_return

}
	echo $html
	echo $bbcode

</SCRIPT>
?>

<form name=formulaire method=post action=action.php onSubmit=\"return verifsubmit()\">
   <table border=0 cellspacing=3 cellpadding=0 width=100% align=center>
           echo "</td></tr>
		   <tr><td valign=top  align=center>HTML :</td><td align=center>";
		   echo"</td></tr>
           <textarea name=html cols=60 rows=10></textarea><br />
           <tr><td valign=top  align=center>BBCODE :</td><td align=center>;
           <textarea name=bbcode cols=60 rows=10></textarea><br />
           echo "</td></tr>
		   <tr><td align=center> </td><td align=center>
           <br /><input type=hidden value=1 name=ok>
		   <input type=submit value=' Envoyer '>
		   </td></tr>
   </table>
</form></center>
";

pouvez vous me dire à quoi c'est du? et aussi si le script vous semble correct car on peut pratiquement dire que c'est mon premier script php

Posté : 17 août 2005, 14:09
par Cyrano
include 'inc_cg_filter.php'; // <<=== Et le ";" ?
Sans compter que tu mélanges sans discernement JavaScript et PHP.. :shock:

Posté : 17 août 2005, 14:14
par NightAngel
Merci en effet j'ai pas encore ce reflexe. Mais maintenant g cela :

Parse error: parse error, unexpected T_VAR in /var/www/free.fr/b/d/adminetwork/test/testbbcode_html.php on line 10

alors que mes variable me semble bien défini.

Posté : 17 août 2005, 14:19
par Cyrano
La déclaration des variables, c'est soit du JavaScript, soir une classe PHP.
Dans ton cas, c'est du JavaScript, il faudrait commencer fermer la balise PHP après l'include, ensuite déclarer une balise <script type="text/javascript"> et ensuite enlever les variables PHP qui sont dans la fonction JavaScript ou alors faire une insertion PHP <?php echo($variable); ?>.

Posté : 17 août 2005, 14:23
par NightAngel
En effet, je m'était rendu compte que j'avais coder du javascript dans du php. Le boulé...

Voila mon script désormais :
<?php

// Ligne indispensable pour la sécurité du site
// if(!(defined('PWSPHP'))){die('Hum hackeur...n\'est-ce pas '.$_SERVER['REMOTE_ADDR'].' ?');}

include 'inc_cg_filter.php';
?>

<script type="text/javascript">

function verifsubmit()
{
	var ok_return = true;
	var html_bbcode = true;
	var bbcode_html = true;
	var html = window.document.formulaire.texte.value;
	var bbcode = window.document.formulaire.texte.value;

    // test si un des champs est rempli
	if (html == '')
	    var html_bbcode = false;
	if (bbcode == '')
	    var bbcode_html = false;

    // test si les 2 champs sont vide
	if (html_bbcode==false)
		if (bbcode_html==false)
		{
			alert('Vous n\'avez renseigné aucun des champs');
			var ok_return = false;
		}
	// test si les 2 champs sont plein
    if (html_bbcode==true)
		if (bbcode_html==true)
		{
			alert('Vous avez renseigné tout les champs');
			var ok_return = false;
		}
	
	if (html_bbcode==true) 
		$convert_html_bbcode=function bbcode_to_html($html);
		else if (bbcode_html==true)
		         $convert_bbcode_html=function bbcode_to_html($bbcode);
		       
    return ok_return

}
</SCRIPT>

<?php
	
	echo $html;
	echo $bbcode;

?>

<form name=formulaire method=post action=action.php onSubmit=\"return verifsubmit()\">
   <table border=0 cellspacing=3 cellpadding=0 width=100% align=center>
		   <tr><td valign=top  align=center>HTML :</td><td align=center>
           <textarea name=html cols=60 rows=10></textarea><br />
           <tr><td valign=top  align=center>BBCODE :</td><td align=center>
           <textarea name=bbcode cols=60 rows=10></textarea><br />
		   <tr><td align=center> </td><td align=center>
           <br /><input type=hidden value=1 name=ok>
		   <input type=submit value=' Envoyer '>
		   </td></tr>
   </table>
</form></center>
il te semble bon ?
Il ne me fait pas d'erreur mais ne fonctionne pas correctement je pense.

Posté : 17 août 2005, 14:28
par NightAngel
Mon fichier action.php
<?php

// Ligne indispensable pour la sécurité du site
// if(!(defined('PWSPHP'))){die('Hum hackeur...n\'est-ce pas '.$_SERVER['REMOTE_ADDR'].' ?');}

// echo $_POST['html'];
// echo $_POST['bbcode'];
echo $_POST['convert_html_bbcode'];
echo $convert_bbcode_html;

?>
ne renvoi rien comme resultat.
Tu c ce que j'ai pu oublier?

Posté : 17 août 2005, 14:32
par Cyrano
C'est quoi ça au juste dans le JavaScript ?

Code : Tout sélectionner

if (html_bbcode==true) $convert_html_bbcode=function bbcode_to_html($html); else if (bbcode_html==true) $convert_bbcode_html=function bbcode_to_html($bbcode);
:?:

Posté : 17 août 2005, 14:36
par NightAngel
En fait je fais une page qui permet de traduire de l'HTML vers du BBCODE et vice versa.

En fait j'utilise des fonction qui sont dans inc_cg_filter.php

En fait avec ce code je veux tester si la variable html_bbcode est egale à true, si c'est le cas, j'utilise la variable $convert_html_bbcode pour stocker le resultat de l'execution de la fonction bbcode_to_html sur la variable ( texte) $html.

Et je fais pareil à l'inverse si c'est pas le cas.

Je sais pas trop si je me suis bien expliqué

Posté : 17 août 2005, 14:40
par Cyrano
ouais, sauf que JavaScript est un langage client, PHP un langage serveur et JavaScript ne reconnait pas les variables PHP pas plus que PHP ne peut interpréter le JavaScript. Toi, tu as sans vergogne mélangé joyeusement tout ça dans la même soupe. Ça n'a aucune chance de fonctionner et à mon avis tu peux tout refaire.

Posté : 17 août 2005, 14:40
par NightAngel
Voici le inc_cg_filter.php
<?php
// ***************************************************************
// Date: 08/08/2005 - File name: inc_cg_filter.php
// Version: 1.02
//
// This is the Coolguys HTML filter class.
//
// It contains BBCode to HTML and HTML to BBCode converters,
// HTML filtering functions, URL and smiley parsing.
// ***************************************************************

class cg_filter {

	var $string;
	var $smiley_path = '../images/smileys/'; // Do not forget trailing '/'
	var $html_filter_prefs = array('entities' => 1, 'nl2br' => 1, 'url_parsing' => 1, 'smileys' => 1); // By default, apply all filtering

	function bbcode_to_html() {

		// ***************************************************************
		// This function parses BBCode into HTML.
		// ***************************************************************

		$pos = strpos($this->string, '[');

		while ($pos !== FALSE) {
			$len = strpos($this->string, ']', $pos + 1) - $pos + 1;
			
			if ($len) { // No need to continue is there is no ]

				$rest = explode('=', substr($this->string, $pos + 1, $len - 2), 2);
				$tag = $rest[0];

				if (($pos2 = strpos($this->string, "[/$tag]", $pos + $len)) === FALSE) { // No end tag
					$tag = NULL;
				} else {
					$param_name = substr($this->string, $pos + $len, $pos2 - $pos - $len);
					$len2 = strpos($this->string, ']', $pos2 + 1) - $pos2 + 1;
				}

				switch($tag) {
				case 'i':
				case 'u':
				case 'b':
				case 's':
			
					$this->string = substr_replace($this->string, "<$tag>", $pos, $len);
					$this->string = substr_replace($this->string, "</$tag>", $pos2, $len + 1);
					break;

				case 'img':

					$replace_str = '<img src="' . $param_name . '" alt="' . basename($param_name) . '" />';

					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'url':

					if (!$rest[1])
						$rest[1] = $param_name;

					$target = NULL;
					if (substr($rest[1], 0, 7) == 'http://')
						$target = ' target="_blank"';

					if ($param_name)
						$replace_str = '<a href="' . $rest[1] . '"' . $target . '>' . $param_name . '</a>';
					else
						$replace_str = '<a href="' . $rest[1] . '"' . $target . '>' . $rest[1] . '</a>';

					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;
			
				case 'align':

					$replace_str = '<div align="' . $rest[1] . '">' . $param_name . '</div>';
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'list':

					$pos_del = strpos($param_name, '[*]');
					$param_name = substr_replace($param_name, '', 0, $pos_del + 3); // Ignore first [*]
					$replace_str = '<ul><li>';
					$replace_str .= str_replace('[*]', '</li><li>', $param_name);
					$replace_str .= '</li></ul>';
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'code':
				case 'quote':

					$replace_str = '<div class="' . $tag . '">' . $param_name . '</div>';

					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'anchor':

					$replace_str = '<a name="' . $param_name . '"></a>';

					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				default:
					// Prevents infinite loops should the string contain "[" char without it being a BBCode
					$pos++;
					break;
				}
			}

			// Repeat
			$pos = strpos($this->string, '[', $pos);
		}
	}

	function html_to_bbcode() {

		// ***************************************************************
		// This function parses HTML into BBCode.
		// ***************************************************************

		$open_tags = array ();

		$pos = strpos($this->string, '<');

		while ($pos !== FALSE) {
			$len = strpos($this->string, '>', $pos + 1) - $pos + 1;
			
			if ($len) { // No need to continue is there is no >
				$rest = explode('=', substr($this->string, $pos + 1, $len - 2), 2);
				$tag = explode(' ', $rest[0]);
				$tag = $tag[0];

				if (($pos2 = strpos($this->string, "</$tag>", $pos + $len)) === FALSE) { // No end tag
					// Let's see if it's a tag without end tag, i.e. <br />, or </div>
					$ok_tags = array ('</div>');
					if (!in_array(substr($this->string, $pos, $len), $ok_tags) && strpos($this->string, '/>', $pos + 1) === FALSE)
						$rest[0] = NULL;
				} else {
					$param_name = substr($this->string, $pos + $len, $pos2 - $pos - $len);
					$len2 = strpos($this->string, '>', $pos2 + 1) - $pos2 + 1;
				}

				switch($rest[0]) {
				case 'i':
				case 'u':
				case 'b':
				case 's':
			
					$this->string = substr_replace($this->string, "[$tag]", $pos, $len);
					$this->string = substr_replace($this->string, "[/$tag]", $pos2, $len + 1);
					break;

				case 'a href':

					$link = explode('"', $rest[1]);
					$replace_str = '[url=' . $link[1]. ']' . $param_name . '[/url]';
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'a name':

					$link = explode('"', $rest[1]);
					$replace_str = '[anchor]' . $link[1] . '[/anchor]';
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'div align':

					$link = explode('"', $rest[1]);
					array_push($open_tags, 'align');
					$replace_str = '[align=' . $link[1] . ']' . $param_name;
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 - $pos);
					break;

				case 'div class':

					$link = explode('"', $rest[1]);
					array_push($open_tags, $link[1]);
					$replace_str = '[' . $link[1] . ']' . $param_name;
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 - $pos);
					break;

				case '/div':

					if (count($open_tags) > 0)
						$replace_str = '[/' . array_pop($open_tags) . ']';
					else
						$replace_str = '';
					$this->string = substr_replace($this->string, $replace_str, $pos, 6);
					break;

				case 'img src':

					$link = explode('"', $rest[1]);
					$replace_str = '[img]'%20.%20$link[1]%20.%20'[/img]';
					$this->string = substr_replace($this->string, $replace_str, $pos, $len);
					break;

				case 'br /':

					$replace_str = '';
					$this->string = substr_replace($this->string, $replace_str, $pos, $len);
					break;

				case 'ul':

					$replace_str = '[list]' . $param_name . '[/list]';
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				case 'li':

					$replace_str = '[*]' . $param_name;
					$this->string = substr_replace($this->string, $replace_str, $pos, $pos2 + $len2 - $pos);
					break;

				default:
					// Prevents infinite loops should the string contain "<" char without it being html
					$pos++;
					break;
				}
			}

			// Repeat
			$pos = strpos($this->string, '<', $pos);
		}

		// Close any open tags, in case the html contains errors
		if (count($open_tags) > 0) {
			foreach($open_tags as $value) {
				$this->string .= '[/' . array_pop($open_tags) . ']';
			}
		}

	}

	function html_filter() {

		// ***************************************************************
		// This function provides basic html filtering.
		// By default, all rules are applied; should you require to
		// disable some rules, the html_filter_prefs array can be used.
		//
		// Ex: $my_class->html_filter_prefs['smileys'] = 0; // No smileys
		// ***************************************************************

		// First we make sure there is not html
		if ($this->html_filter_prefs['entities'])
			$this->string = htmlspecialchars($this->string, ENT_NOQUOTES);

		// Smileys
		if ($this->html_filter_prefs['smileys']) {
			$smileys = array (':)' => 0, ':-)' => 0, ';)' => 1, ';-)' => 1, ':D' => 2, ':-D' => 2, ':P' => 3, ':-P' => 3, ':p' => 3, ':-p' => 3, ':(' => 4, ':-(' => 4);
			$filename = array('happy.gif', 'wink.gif', 'biggrin.gif', 'tongue.gif', 'sad.gif');

			foreach ($smileys as $key => $value) {
				$img_url = '<img src="' . $this->smiley_path . $filename[$value] . '" alt="' . $key . '" />';
				$this->string = str_replace($key, $img_url, $this->string);
			}
		}

		// This automatically converts new lines and tabs
		if ($this->html_filter_prefs['nl2br']) {
			$this->string = nl2br($this->string);
			$this->string = str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', $this->string);
		}

		// Automatic URL parsing
		if ($this->html_filter_prefs['url_parsing']) {
			// For 'http://example.com/?id=' type links
			$this->string = ereg_replace('[ ]+([a-z]+://[-a-z0-9A-Z&_\/\.\?\=]+)[ ]+', ' <a href="\\1" target="_blank">\\1</a> ', $this->string);
			// For 'www.example.com' type links
			$this->string = ereg_replace('[ ]+(www\.[-a-z0-9A-Z\.]+\.[-a-z0-9A-Z&_\/\.\?\=]+)[ ]+', ' <a href="http://\\1" target="_blank">http://\\1</a> ', $this->string);
		}
	}

}
?>

Posté : 17 août 2005, 14:43
par NightAngel
Donc ok je peut recommencer... il suffit de ne pas se décourager..

Donc ce qui pose problème, c'est de vouloir mettre une fonction php dans du javascript c'est bien cela?

Puis je recuper des variable du javascript pour les mettres dans mon php?

Posté : 17 août 2005, 14:51
par Cyrano
Va visiter cette page, c'est instructif.

Posté : 17 août 2005, 15:13
par NightAngel
merci