dlcmpls Posted February 10, 2007 Share Posted February 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 Which is line 7? Is that really all of the code? The second call is missing an argument, but that wouldn't show this error. Make 'Dave'); all be on the same line. Quote Link to comment Share on other sites More sharing options...
dlcmpls Posted February 10, 2007 Author Share Posted February 10, 2007 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); Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted February 10, 2007 Share Posted February 10, 2007 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 When you paste your code in here, highlight it and press the # button in the editor to put code tags around it. As ken said, the code is fine. Try using just a plain text editor and writing it, see if that helps. Quote Link to comment Share on other sites More sharing options...
dlcmpls Posted February 10, 2007 Author Share Posted February 10, 2007 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! Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 10, 2007 Share Posted February 10, 2007 Try the Textpad editor, it's a really great one Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.