Jump to content

My User Defined Function Throws An Error


dlcmpls

Recommended Posts

Hello everyone.  I'm trying to write my first function and having all kinds of trouble.

 

Here's what I've got so far:

 

<?php

 

function clean($text) {

  return strip_tags($text);

}

 

 

$firstname = clean('Dave <br>');

 

 

clean();

?>

 

I am basically just trying to get the function to remove any html from a variable, but I get this error message:

 

Parse error: parse error in /Library/WebServer/Documents/php_default_website/dev/contact_us/test.php on line 7

 

Any suggestions?

 

dlc

Link to comment
https://forums.phpfreaks.com/topic/37926-my-user-defined-function-throws-an-error/
Share on other sites

Jesi you are a saint.  I can't tell you how much I appreciate your help.  In trying to get this to work, I've tried to reduce the code to the bare minimum.  Anyway, here's a repaste of the code (and yep, this is all the code):

 

<?php

 

function clean($text) {

  return strip_tags($text);

}

 

 

$firstname = clean('Dave <br>');

 

 

clean();

?>

 

The  $firstname = clean  is all on one line.

 

I tightened up the code a bit so the new error message is:

 

Parse error: parse error in /Library/WebServer/Documents/php_default_website/dev/contact_us/test.php on line 3

 

 

Line 3 is: return strip_tags($text);

There may be extraneous characters in your file that are causing the problem. This code works fine:

<?php
function clean($text) {
       return strip_tags($text);
            }
$firstname = clean('<br>Dave<br>');
echo $firstname;
?>

 

Ken

Thanks Ken.  That does indeed work.  I think you were right about the extraneous characters.  I was using DreamWeaver to edit the file.  I used BBEdit instead, cleaned up all the spaces etc and it works fine now.

 

Frustrating!

 

But thank god for the forum users!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.