[Last Call] Learn how to a build a cloud-first strategyRegister Now


Cstr Equivalent function in PHP

Posted on 2006-05-22
Medium Priority
Last Modified: 2008-02-01
I am converting an ASP script to PHP. The ASP script uses the Cstr function--is there an equivalent in PHP?
Question by:jbreg
LVL 33

Assisted Solution

snoyes_jw earned 1000 total points
ID: 16738003
"You can convert a value to a string using the (string)  cast, or the strval() function. String conversion is automatically done in the scope of an expression for you where a string is needed."

LVL 16

Accepted Solution

dr_dedo earned 1000 total points
ID: 16738186
there is no data type in php, meaning $x=333 is almost the same as $x="333".
$d = 555;
echo $d; //<--- this will echo 555 and you can deal with as 555

mean while, there is a couple of exceptions:
1- boolean
$d = false;
echo $d; //<--- will echo nothing

2- integers
echo $a[2]; //<-- echo nothing (string is considered as some sort of array)

so, to over come this, u can use the following
echo $b[2]; //<-- echo 5 (as $b is a string)

for the boolean thing, u can use some sort of conditions
$x = ($x===false)?"false":"true";

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question