PHP ECHO not visible in source code of HTML page

This code works fine. II'm using Google maps and Google Places API and store the response in an array and echo it.
But what I don't get, why is the API response visible in the browser but it is NOT there when I view the source code of the page? When I view the source code I just see the divs.



<?php
				$bizArray = file_get_contents("https://maps.googleapis.com/maps/api/place/search/json?location=".$jsonLAT.",".$jsonLNG."&radius=".$searchRadius."&types=".$category."&sensor=false&key=".$api_key);
				$bizArray = json_decode($bizArray, true);
				//print_r($bizArray);
				foreach ($bizArray['results'] as $key => $value) {
					$place_id = $value['place_id'];
					$bizData = file_get_contents("https://maps.googleapis.com/maps/api/place/details/json?placeid=".$place_id."&sensor=false&key=".$api_key);
					$bizData = json_decode($bizData, true);
					$bizItem = $bizData['result'];
					//print_r($bizItem); continue;
					?>
					<li class="listItem" category="<?php echo $category;?>" placeid="<?php echo $place_id;?>">
					<span class="item_name"><?php echo $bizItem['name'];?></span> - <span class="item_area"><?php echo $bizItem['vicinity'];?></span><br />
					<div class="item_details" style="margin-top: 5px;">
					<?php
						if(isset($bizItem['website']) && $bizItem['website']!=""){ ?>
							<span class="data_detail website">Website: <?php echo $bizItem['website']; ?></span><br />
						<?php }
						if(isset($bizItem['url']) && $bizItem['url']!=""){ ?>
							<span class="data_detail url">Google Plus: <?php echo $bizItem['url']; ?></span><br />
						<?php }
						if(isset($bizItem['formatted_phone_number']) && $bizItem['formatted_phone_number']!=""){ ?>
							<span class="data_detail formatted_phone_number">Phone: <?php echo $bizItem['formatted_phone_number']; ?></span><br />
						<?php }
						if(isset($bizItem['opening_hours']) && !empty($bizItem['opening_hours'])){
							$opening_hours = $bizItem['opening_hours'];
							$html = '<div class="data_detail opening_hours">';
							if($opening_hours[open_now]) {
								$html .= '<span>Open Now: Yes</span><br />';
							}
							if($opening_hours['periods'] && !empty($opening_hours['periods'])) {
								if($opening_hours['periods'][0]['time']==0 && $opening_hours['periods'][0]['time']==0) {
									$html .= '<span>Time: Always Open</span><br />';
								} else {
									$timesArr = array();
									foreach($opening_hours['periods'] as $period) {
										$day; $opening; $closing; $time;
										$opening = str_split($period['open']['time']);
										$opening = $opening[0].$opening[1].":".$opening[2].$opening[3];
										$closing = str_split($period['close']['time']);
										$closing = $closing[0].$closing[1].":".$closing[2].$closing[3];
										$time = $opening."-".$closing;
										switch($period['open']['day']){
											case 0: $day = 'Sun'; break;
											case 1: $day = 'Mon'; break;
											case 2: $day = 'Tus'; break;
											case 3: $day = 'Wed'; break;
											case 4: $day = 'Thu'; break;
											case 5: $day = 'Fri'; break;
											case 6: $day = 'Sat'; break;
											default: $day = '';
										}
										array_push($timesArr, $day." ".$time);
									}
									$html .= '<span>Day/Time: '. implode(', ', $timesArr) .'</span><br />';
								}
							}
							$html .= '</div><br />';
							echo $html;
						}
						if(isset($bizItem['price_level']) && $bizItem['price_level']!=""){
							switch($bizItem['price_level']){
								case 0: $price_level = "Free"; break;
								case 1: $price_level = "Inexpensive"; break;
								case 2: $price_level = "Moderate"; break;
								case 3: $price_level = "Expensive"; break;
								case 4: $price_level = "Very Expensive"; break;
								default: $price_level = "";
							} ?>
							<span class="data_detail price_level">Price Level: <?php echo $price_level; ?></span><br />
						<?php }
						if(isset($bizItem['rating']) && $bizItem['rating']!=""){ ?>
							<span class="data_detail rating">Rating: <?php echo $bizItem['rating']; ?></span><br />
						<?php }
						if(isset($bizItem['aspects']) && !empty($bizItem['aspects'])){
							$aspectsArr = array();
							foreach($bizItem['aspects'] as $aspect) {
								array_push($aspectsArr, $aspect['type']." - ".$aspect['rating']);
							} ?>
							<span class="data_detail aspects">Rating Aspects: <?php echo implode(', ', $aspectsArr); ?></span><br />
						<?php }
						if(isset($bizItem['review_summary']) && $bizItem['review_summary']!=""){ ?>
							<span class="data_detail review_summary">Review Summary: <?php echo $bizItem['review_summary']; ?></span><br />
						<?php }
						if(isset($bizItem['reviews']) && !empty($bizItem['reviews'])){
							$html = '<div class="data_detail reviews"><span>Reviews: </span><br />';
							foreach($bizItem['reviews'] as $review) {
								$html .= '<div class="user_review">';
								$html .= '<span>'. (strtolower($review['author_name'])=='a google user' ? "Anonymous" : $review['author_name']).'</span><br />';
								if(isset($review['rating'])){
									$html .= '<span>Rating: '.$review['rating'].'</span><br />';
								}
								if(isset($review['aspects']) && !empty($review['aspects'])){
									$aspectsArr = array();
									foreach($review['aspects'] as $aspect) {
										array_push($aspectsArr, $aspect['type']." - ".$aspect['rating']);
									}
									$html .= '<span>Rating Aspects: '.implode(', ', $aspectsArr).'</span><br />';
								}
								if(isset($review['text']) && $review['text'] != ""){
									$html .= '<span>'.$review['text'].'</span><br />';
								}
								$html .= '</div>';
							}
							$html .= '</div><br />';
							echo $html;
						} ?>
					</div>
					</li>
				<?php }
				?>
				</ol>
			</div>
		<?php
		} ?>

Open in new window

seoptiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Copied the script verbatim and installed it here:
http://iconoun.com/demo/temp_seopti.php

Is there a URL we can use to see this effect, or can you please post a working script that demonstrates the phenomenon?
0
seoptiAuthor Commented:
Thanks, yes it is:
http://www.local-health.net/california/banning/rachael-slomovic-31660.html

Please click on the tab "Nearby" and scroll down. There are three categories, Dentists, Doctors, Hospitals. The results for the businesses come from the Google Places API via JSON and I echo them with the code above. But it's a mystery for me why this is not visible in the source code of the browser.
0
Julian HansenCommented:
Can't see where you are echoing the output in the link provided?

What are we looking for?

Original code post - dumps of var's (print_r) were commented out.

Can you tell us specifically what you are seeing in the browser that you are not seeing in the source?
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

seoptiAuthor Commented:
Please go to this url:
http://www.local-health.net/california/banning/rachael-slomovic-31660.html

Click on the Nearby Tab and scrool down, you will find:
DENTISTS
1.    Beaumont Dental Group - 930 Beaumont Ave, Beaumont
...
DOCTORS
....

HOSPITALS
....

Now all this text (the businesses) from the Places API response is not visible in the browser source.
0
seoptiAuthor Commented:
This is what I see in the browser source code:

<div id="poiListData">
					<div class="hidden" id="dentist_items">
				<div class="data_title">Dentists</div>
				<ol class="data_items">
								</ol>
			</div>
					<div class="hidden" id="doctor_items">
				<div class="data_title">Doctors</div>
				<ol class="data_items">
								</ol>
			</div>
					<div class="hidden" id="hospital_items">
				<div class="data_title">Hospitals</div>
				<ol class="data_items">
								</ol>
			</div>

Open in new window

0
Kim WalkerWeb Programmer/TechnicianCommented:
The response from google maps contains client-side scripts that modify the page after it loads. The source code for the page never changes, but the rendering of the page changes when the scripts are executed. The source code is always exactly what is delivered by the web server. You should, however, since you're inserting the returned script tag via php, be able to see that script tag in the page source code. But most of the google source code is collected and inserted after the page is loaded. Make sense?
0
Ray PaseurCommented:
This is probably loaded by an AJAX request.  You will not see it in the "view source" which is what the browser saw at the start of rendering the page.  It only appears after the background script injects something into the DOM.

This article shows the basics of jQuery and AJAX.  You can try these scripts and use "view source" to get a small test case that illustrates what is going on.
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/A_10712-The-Hello-World-Exercise-with-jQuery-and-PHP.html
0
seoptiAuthor Commented:
Yes it is JSON and it is AJAX. I tried to store that JSON response in an array and output it. I think it's harder than I thought.
0
Ray PaseurCommented:
At some level the JSON response should be a string of text.  You might try using it as if it were a string variable and not a JSON data type to see if that will reveal its secrets.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
I agree with the comments about AJAX loading of content - however I did a test with FF
Snippet of browser source below
 Banning health services with Zip Code 92220:<br>
<span style="line-height: 1.6em;">

<a href="/california/banning/john-alexander-63069.html">John Alexander</a>
	Alexander Dental Lab  <br>

			<a href="/california/banning/bakhtiar-ahmad-62451.html">Bakhtiar Ahmad</a>
	Bakhtiar Ahmad MD  <br>

			<a href="/california/banning/david-j-scanlan-64332.html">David J Scanlan</a>
	Banning Chiropractic  <br>

			<a href="/california/banning/471-n-san-gorgonio-ave-64333.html">Banning Dental Ctr</a>
	 <br>

			<a href="/california/banning/lisa-wilson-64334.html">Lisa Wilson</a>
	Banning Family Dentistry  <br>

			<a href="/california/banning/mario-bertumen-31658.html">Mario Bertumen</a>
	Banning Healthcare  <br>

			<a href="/california/banning/tiffany-holmes-64336.html">Tiffany Holmes</a>
	Banning Pediatric Clinic  <br>

			<a href="/california/banning/paul-nemeth-31659.html">Paul Nemeth</a>
	Banning Psychological Assoc  <br>

			<a href="/california/banning/264-n-highland-spgs-ave-5b-64362.html">Beaumont Dental Ctr</a>
	 <br>

			<a href="/california/banning/janna-redmond-64367.html">Janna Redmond</a>
	Beaver Medical Group  <br>

			<a href="/california/banning/celeste-lucas-65299.html">Celeste Lucas</a>
	Butterfield Dental  <br>

			<a href="/california/banning/anthony-lopez-31723.html">Anthony Lopez</a>
	Cherry Valley Health Care  <br>

			<a href="/california/banning/daniel-bessesen-64754.html">Daniel Bessesen</a>
	Daniel Bessesen MD  <br>

			<a href="/california/banning/6350-w-ramsey-st-a-64984.html">Dental Works</a>
	 <br>

			<a href="/california/banning/trudy-wright-65011.html">Trudy Wright</a>
	Desert Hematology Oncology  <br>

			<a href="/california/banning/joy-oliverio-67768.html">Joy Oliverio</a>
	Exciting Skin Laser Ctr  <br>

			<a href="/california/banning/norma-saucedo-67878.html">Norma Saucedo</a>
	Friendly OBGYN Medical Grp  <br>

			<a href="/california/banning/denise-frank-68031.html">Denise Frank</a>
	Gambro Healthcare  <br>

			<a href="/california/banning/john-cassar-31874.html">John Cassar</a>
	Golden Meadows  <br>

			<a href="/california/banning/nita-beloso-76245.html">Nita Beloso</a>
	Golden View Guest Home  <br>

			<a href="/california/banning/hank-lefler-76317.html">Hank Lefler</a>
	Haven Laboratory  <br>

			<a href="/california/banning/c-ane-padilla-76325.html">C Ane Padilla</a>
	Healing By Design  <br>

			<a href="/california/banning/264-n-highland-springs-1-d-76369.html">Hematology Oncology</a>
	 <br>

			<a href="/california/banning/3158-w-ramsey-st-76497.html">Indian Health Inc</a>
	 <br>

						</span><br><br>

Open in new window

0
Chris StanyonWebDevCommented:
Others have already hit the nail on the head - the AJAX injection doesn't change what you see when you 'View Source'.

If you're doing a lot of development work and need a more detailed look at what you're doing, consider using some of the web developer browser plugins. For example, the Web Developer plugin for Firefox adds a menu option that lets you view the 'Generated Source'. This would show you the source after the AJAX injection and you wouldn't have the problem.
0
Ray PaseurCommented:
@ChrisStanyon: Good call.  I think there may be some similar features available in Chrome Dev Tools.
https://developer.chrome.com/devtools
http://discover-devtools.codeschool.com/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.