Solved

Variable to string

Posted on 2014-02-04
4
286 Views
Last Modified: 2014-02-04
I'm looking for a way to covert a variable to a string. I thought I could use settype or cast or var_dump but all don't seem to convert the variable name only, so for example:-

 $varName = "hello";

 //should echo out varName
 Echo variableToString($varName);

Open in new window


I cannot see any examples, or google results as a solution, does anyone have any ideas?

Thank you in advance
0
Comment
Question by:tonelm54
  • 3
4 Comments
 

Accepted Solution

by:
tonelm54 earned 0 total points
ID: 39833550
Found the answer:-
 
<?php
      $my_var = 1;
      echo var_name ($my_var);
?>

Open in new window

0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39834277
You're kidding, right?  What is the var_name() function?
http://php.net/manual-lookup.php?pattern=var_name&scope=quickref
0
 

Author Comment

by:tonelm54
ID: 39834760
Found the article http://mach13.com/how-to-get-a-variable-name-as-a-string-in-php

Hadnt tried it out, got asked about it, did some google'ing and couldnt find anything then opened a question up on the way home, then found the article on reading something else, didn't have access to anything to test it so closed the question, yet on reading further into the article he writes the function.

In defense (not that it is one) I was concerned that I couldnt find thw function on php.net but assumed that it just might have been undocumented (not that it would have been)

Apologies for any one who finds this and thinks var_name exists, ill ask a moderator to assist in modifing the questions solution
0
 

Author Comment

by:tonelm54
ID: 39834774
Actually opened a kinda spin off question as it didnt really fill the requirement at  Q_28356765 if anyone is reading this, which I will test out first, before accepting.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

733 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