?
Solved

Variable to string

Posted on 2014-02-04
4
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 111

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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

752 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