Solved

Variable to string

Posted on 2014-02-04
4
280 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 108

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
XSS cleaning when using ajax & json encode 5 39
Not needed 13 57
Getting info from database not working 6 16
PHP json decode 9 20
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.
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 …

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

18 Experts available now in Live!

Get 1:1 Help Now