473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Use of isset () in a string variabel

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
4 1778
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marcus | last post by:
I'm really confused with something I never had any problems with before... I have a form with a textbox called password. On the second page that $password is posted to, if I test isset($password)...
3
by: christian9997 | last post by:
Hi I don't seem to understand the way isset works. Here is some Javascript code that makes a call using PHP: // USER CAME BACK TO CHANGE LANGUAGE if (<?echo isset($_REQUEST)?>) {...
1
by: alain dhaene | last post by:
Hi, Is it possible to make the access for a variabel private? Alain.
2
by: rw | last post by:
In php 5.0.3 i found that $s="a"; if(isset($s->prop)) echo "surprise"; In previous php it was false; Is it bug? -- Rob Was
14
by: juglesh | last post by:
"$string = isset($xyz) ? $xyz : "something else";" Hello, someone gave code like this in another thread. I understand (by inference) what it does, but have not found any documentation on...
8
by: Paw Pedersen | last post by:
Is there a way to save a variabel that can be access from a static method? I hope there would be some way to save it in memory so I don't have to save it in a file. It's only for a few minutes the...
25
by: wd | last post by:
I want my server to send a 404 header if a URL with a query string is requested. So if a browser or spider requests something like www. my_site .com?p=chair they would get a 404... But if they...
0
by: inqa | last post by:
i have new variabel width and height, both of them have a value :(width=*&^ and height=%^*) . i want to insert that variable and their's value to another header image, but i can't, may i get the...
2
by: yawnmoth | last post by:
<?php $var = 'test'; echo isset($var) ? 'true' : 'false'; echo '<br>'; echo isset($var) ? 'true' : 'false'; ?> Why does that result in this output?:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.