By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,180 Members | 1,012 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,180 IT Pros & Developers. It's quick & easy.

Use of isset () in a string variabel

P: n/a
Hello,

What I try to do is create a string variabel with some intelligence.

I want this variabel to read the information sent by another page and
interpret the result.

The idea is that is a variabel is set, a line break is printed.

First question is if this is possible? Second if so, what should be the
correct syntax? I have written it like this, but this errors.

$string="{$_POST['name']}{if (isset($_POST['name'])){print ("<br>");}";

Thanks in advance for your help!

Brian

Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Brian Olivier wrote:
What I try to do is create a string variabel with some intelligence.

I want this variabel to read the information sent by another page and
interpret the result.

The idea is that is a variabel is set, a line break is printed.

First question is if this is possible? Second if so, what should be
the correct syntax? I have written it like this, but this errors.

$string="{$_POST['name']}{if (isset($_POST['name'])){print
("<br>");}";


You can't put code inside the curlies {} in a string.

I'm not sure I understand exactly what you are wanting to do, but if you
want to print a line break if the value is set, or do something else if
it is not, then you probably want to do it like this:

if(isset($_POST['name'])) {
// do something
}
else {
// do something else
}

If you want to assign the value to a variable you can do it like this:

$string = isset($_POST['name']) ? $_POST['name'] : "something else";

With this example, if $_POST['name'] is set then $string will be
populated with that value. If it's not then it will be populated with
"something else".

HTH

--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Jul 17 '05 #2

P: n/a
Hello,

The first option is what I want, but the fact that I can't put code in
the curlies in a string is what I wanted to know. I was hoping for a
smart string, but I will program the intelligence outside of the
string!

Thanks for your help!

Brian

Jul 17 '05 #3

P: n/a
Brian Olivier wrote:
Hello,

The first option is what I want, but the fact that I can't put code in
the curlies in a string is what I wanted to know. I was hoping for a
smart string, but I will program the intelligence outside of the
string!

You seem to be trying to send code from one script to be executed in a
second - is that correct?

If so, look at 'eval' and 'create_function' which will do what you want, but
you should really think long & hard about how to implement this securely.
You certainly don't want to execute any code sent back from a browser.
Better ways of doing this would be:

1) don't do it at all
2) encrypt the code before sending it out to the browser / decrypt and
validate it before executing it
3) don't send it to the browser - store it in a session variable.

HTH

C.
Jul 17 '05 #4

P: n/a
On 10 May 2005 01:08:44 -0700, "Brian Olivier" <br***@olivier.com>
wrote:
Hello,

The first option is what I want, but the fact that I can't put code in
the curlies in a string is what I wanted to know. I was hoping for a
smart string, but I will program the intelligence outside of the
string!


you can do this:

<?php
echo(isset($_POST['name']))?'<br>':'';
?>

if $_POST['name'] is set, a <br> will be echoed, if it is not, nothing
will be echoed

hth,
B.

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.