Hi There,

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.

Regards

Member Avatar

A text editor with a find command.??

Hi Diafol,

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.

Regards

You mean, assuming this:

$search = 'A';
//...
$search = 'B';
//...
$search = 'C';
//...

You want to see A, B and C?

Hi Pritaeas,

I would search for occurrences of $search and display the code.
Example.

<?php
$search = 'A';
$search. = 'B';
$search. = 'C';

$Data = 'D';

echo $search;
?>

Display Just $search

$search = 'A';
$search. = 'B';
$search. = 'C';
echo $search;

Regards

Open the php file, with file(). Then loop each line, if the variable is there (using strpos()), echo the line.

Member Avatar

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.

phpstorm_xdebug.PNG

commented: Woop PhpStorm :D +7
Member Avatar

Ah. Just got your cross-post.

Hi Pritaeas,

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.

Regards