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
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);

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.