0

I am pulling values submitted from a form and displaying them in a couple different formats. Sometimes I need the values to be echo-ed in lowercase and sometimes I need any capitalization preserved, depending on the section of the page. However, I need all values to have the slashes stripped out.

I am using the following format to echo the lowercase values

<?php echo strtolower ( $keyword ); ?>

This is working fine. Though, adding 'stripslashes' to that is throwing an error. I'm sure I'm not formatting it correctly.

How do I accomplish both of these items?

Update

I was simply asking a question related to PHP formatting and syntax but, in order to appease Oli Charlesworth . . .

<?php echo stripslashes strtolower ( $keyword ); ?>

This is the code I had tried. And this is the error it was throwing ...

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content/u/s/e/username/html/folder/code.php on line 63

Batfan
  • 7,966
  • 6
  • 33
  • 53
  • 5
    Argh, another "Here is some code that works. I have some other code that doesn't work. What is the problem?". What is your problematic code? And what is the error? – Oliver Charlesworth Jan 28 '11 at 00:15
  • 2
    Use example one from Alex or myself - you need to nest the function calls is all. – christophmccann Jan 28 '11 at 00:25
  • 1
    This question hints at a misunderstanding of the language syntax. You should read a [few tutorials](http://stackoverflow.com/questions/4554936/php-recommended-tutorials) before you venture into other topics and **download** the php manual. – mario Jan 28 '11 at 00:34
  • @mario - Agreed. I am a PHP novice. I simply posted this question based on time restraints. I needed to get this to production. – Batfan Jan 28 '11 at 00:38
  • These are not "slashes", they're "backslashes". – bart Jan 28 '11 at 03:53

2 Answers2

2
echo strtolower(stripslashes($keyword));

Should do it.

Also note, you could do...

<span style="text-transform: lowercase"><?php echo stripslashes($keyword); ?></span>

Update

Your code...

<?php echo stripslashes strtolower ( $keyword ); ?>

...is not correct code, because each function needs to take its arguments within parenthesis. You need to wrap them in their respective parenthesis - so the return value from the inner becomes the argument for the outer.

alex
  • 479,566
  • 201
  • 878
  • 984
  • 2
    Thank you for actually providing a useful answer :) – Batfan Jan 28 '11 at 00:33
  • "because each function needs to take its arguments within parenthesis" except `echo` – bart Jan 28 '11 at 03:50
  • 3
    @bart `echo()` isn't a function, but a [language construct](http://stackoverflow.com/questions/1180184/what-is-the-difference-between-a-language-construct-and-a-built-in-function-in) (or more generally, an operator). – alex Jan 28 '11 at 04:22
1

You really need to provide the code you are using to stripslashes before we can assist properly.

But the following code should stripslashes:

<?php echo strtolower(stripslashes($keyword)); ?>

I cant think of any reason why that wouldn't work unless you are using an ancient version of PHP. You could also use (although this will remove all slashes including //):

<? echo strtolower(str_replace("\\", "", $keyword)); ?>

You will need to utilise some kind of conditional to decide when to keep capitals or not.

mario
  • 144,265
  • 20
  • 237
  • 291
christophmccann
  • 4,181
  • 7
  • 42
  • 66