I'm checking if I can get all the occurrences of a variable in a php file. What will the best and easest method be?
Any help is greatly appreciated.
A text editor with a find command.??
Sorry, I want to display all the occurrences of example "$search" from where it starts to where it ends.
I'm using get_defined_vars to get all the variables that's set but now I want to display all of the occurrences is sequence.
You mean, assuming this:
$search = 'A'; //... $search = 'B'; //... $search = 'C'; //...
You want to see A, B and C?
I would search for occurrences of $search and display the code.
<?php $search = 'A'; $search. = 'B'; $search. = 'C'; $Data = 'D'; echo $search; ?> Display Just $search $search = 'A'; $search. = 'B'; $search. = 'C'; echo $search;
Open the php file, with
file(). Then loop each line, if the variable is there (using
strpos()), echo the line.
Do you want to watch the variable as it passes through your code?
You can use XDEBUG or Zend Debug.
Here's XDEBUG in action with PHP Storm. I couldn't really do without it. The alternative is horrendous - i.e. echo all over the place.
Ah. Just got your cross-post.
Thanks for the telling me about strpos. Is there a way to use next variable if strpos find a true value. I'm running a foreach loop to check if the variables match up and if they do I would like to go to the next variable in the foreach loop.