0

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

3
Contributors
8
Replies
57
Views
2 Years
Discussion Span
Last Post by LRNPHP
0

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

Edited by LRNPHP: More Info

0

You mean, assuming this:

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

You want to see A, B and C?

0

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

1

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

2

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

Votes + Comments
Woop PhpStorm :D
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.