Cstr Equivalent function in PHP

Posted on 2006-05-22
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

    "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

    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";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now