When I try to run this page (video.php), I get the following error:
Parse error: syntax error, unexpected $end in /base/path/masked/inc/functions.php on line 37
The strange thing is "functions.php" has more than 37 lines... why is it detecting an end of file there? I don't think I'm missing any parens or brackets since each function is only one statement (a print statement) long.
I've done several things to try and fix the problem. If I remove the statements in the function definition for both print_head() and print_foot(), the error goes away (the rest of the page works fine). If I remove statements in either one of the functions, I get the same error, just on a different line. If I move the function definitions around on the page, I get the same error. I've even tried removing parts of the print statement, but I still get the same error.
EDIT:
'videos/transfer/playlist' is an example file that get_vids() loads. It's a flat txt file with an even number of lines; odd lines are the name of a video file, and even lines are the title that go with the preceding file. I've tested to make sure get_vids() works as expected.
EDIT:
Here's what I get when I try to run everything from the command line:
$ php -l video.php
No syntax errors detected in video.php
$ php video.php
Parse error: syntax error, unexpected $end in /home/nova20/http-dir/orientation/inc/functions.php on line 37
$ php -l inc/functions.php
Parse error: syntax error, unexpected $end in inc/functions.php on line 37
Errors parsing inc/functions.php
Here's my code:
video.php:
<?php
include('inc/functions.php');
$type=$_GET['type'];
if($type == '') {
$type = 'transfer';
}
$vidno = $_GET['vid'];
if($vidno == '') {
$vidno = 1;
}
$vidindex = $vidno - 1;
$videos = get_vids($type);
$filename = $videos[$vidindex]['file'];
$title = $videos[$vidindex]['title'];
$basedir = "videos/$type";
$vidfile = "$basedir/$filename";
if($vidfile != '') {
$extra = '<script src="/flowplayer/flowplayer-3.1.4.min.js"></script>';
print_head($title, $extra);
print <<<ENDHTML
<p>
<a
href='$vidfile'
style="display:block;width:640px;height:498px;"
id="player"
></a>
</p>
<p id="contlink" style="display:none">
Click Here to continue
</p>
<script language="JavaScript">
flowplayer(
"player",
"/flowplayer/flowplayer-3.1.5.swf",
{
clip: {
onFinish: function(){
//window.location = "done.php";
//alert('done!');
document.getElementById('contlink').style.display = "block";
}
},
plugins: {
controls: {
play:true,
volume:true,
mute:true,
time:true,
stop:true,
fullscreen:true,
scrubber:false
}
}
}
);
</script>
ENDHTML;
print_foot();
} else {
print_head('OOPS!');
print <<<ENDERROR
<h1>OOPS!</h1>
<p>
It looks like there's no video here. <a onclick="history.go(-1);return false;" href="#">Go back</a> and try again.
</p>
ENDERROR;
print_foot();
}
?>
inc/functions.php (where I think the problem is):
<?php
function get_vids($type) {
$base = "videos/$type";
$playlist = "$base/playlist";
$vidinfo = file($playlist);
$videos = array();
for($i = 0; $i < count($vidinfo); $i += 2) {
$filename = trim($vidinfo[$i]);
$title = trim($vidinfo[$i+1]);
if($filename != '') {
$index = $i / 2;
$video['file'] = $filename;
$video['title'] = $title;
$videos[$index] = $video;
}
}
return($videos);
}
function print_head($title, $extra = '') {
print <<<ENDHEAD
<html>
<head>
<title>$title</title>
$extra
</head>
<body>
ENDHEAD;
}
function print_foot() {
print <<<ENDFOOT
</body>
</html>
ENDFOOT;
}
?>
videos/transfer/playlist
1.flv
Introduction
2.flv
Why am I doing this?
3.flv
What can I access with RAIN?
4.flv
How do I access my RAIN Account?
5.flv
How do I Check my registration status?
6.flv
Evaluating transfer credit
7.flv
Transferable degrees
8.flv
Physical Education and History
9.flv
Regents exemptions
10.flv
Academic status
11.flv
How to find my academic advisor?
12.flv
Is Financial Aid available?
13.flv
How do I check my financial aid status?
14.flv
How do I transfer my hope scholarship?
15.flv
Payment information
16.flv
Student Services (Part 1)
17.flv
Student Services (Part 2)
18.flv
Student Services (Part 3)
19.flv
Campus Bookstore
20.flv
Where can I eat on Campus?
21.flv
Where can I live on Campus?
22.flv
How do I register for Parking?
23.flv
Still Have questions?
It's not detecting an end-of-file, per se, but a logical end of the executable lines of code.
Make sure your HEREDOC end tokens (ENDHEAD; and ENDFOOT;) have no spaces before them - the moment they're not the first token on the line, they don't register as HEREDOC end tokens but as an arbitrary string within, so your HEREDOC eats up more of the codeblock.
That's the only thing that comes to mind - php -l <your functions.php> netted me no errors (but adding a space before ENDHEAD; gave me the error you described).
I've fixed the code for you:
<?php
include('inc/functions.php');
$type=$_GET['type'];
if($type == '') {
$type = 'transfer';
}
$vidno = $_GET['vid'];
if($vidno == '') {
$vidno = 1;
}
$vidindex = $vidno - 1;
$videos = get_vids($type);
$filename = $videos[$vidindex]['file'];
$title = $videos[$vidindex]['title'];
$basedir = "videos/$type";
$vidfile = "$basedir/$filename";
if($vidfile != '') {
$extra = '<script src="/flowplayer/flowplayer-3.1.4.min.js"></script>';
print_head($title, $extra);
?>
<p>
<a
href='<?=$vidfile;?>'
style="display:block;width:640px;height:498px;"
id="player"
></a>
</p>
<p id="contlink" style="display:none">
Click Here to continue
</p>
<script language="JavaScript">
flowplayer(
"player",
"/flowplayer/flowplayer-3.1.5.swf",
{
clip: {
onFinish: function(){
//window.location = "done.php";
//alert('done!');
document.getElementById('contlink').style.display = "block";
}
},
plugins: {
controls: {
play:true,
volume:true,
mute:true,
time:true,
stop:true,
fullscreen:true,
scrubber:false
}
}
}
);
</script>
<?php
print_foot();
} else {
print_head('OOPS!');
?>
<h1>OOPS!</h1>
<p>
It looks like there's no video here. <a onclick="history.go(-1);return false;" href="#">Go back</a> and try again.
</p>
<?php
print_foot();
}
?>
You can just open and close the php tags around the html that you want to display - as you will see above :)
Hope that helps
Related
So I have a simple html page that looks like this.
<html>
<head>
<?php include("scripts/header.php"); ?>
<title>Directory</title>
</head>
<body>
<?php include("scripts/navbar.php"); ?>
<div id="phd">
<span id="ph">DIRECTORY</span>
<div id="dir">
<?php include("scripts/autodir.php"); ?>
</div>
</div>
<!--Footer Below-->
<?php include("scripts/footer.php"); ?>
<!--End Footer-->
</body>
</html>
Now, the problem is, when I load the page, it's all sorts of messed up. Viewing the page source code reveals that everything after <div id="dir"> is COMPLETELY GONE. The file ends there. There is no included script, no </div>'s, footer, or even </body>, </html>. But it's not spitting out any errors whatsoever. Just erasing the document from the include onward without any reason myself or my buddies can figure out. None of us have ever experienced this kind of strange behavior.
The script being called in question is a script that will fetch picture files from the server (that I've uploaded, not users) and spit out links to the appropriate page in the archive automatically upon page load because having to edit the Directory page every time I upload a new image is a real hassle.
The code in question is below:
<?php
//Define how many pages in each chapter.
//And define all the chapters like this.
//const CHAPTER_1 = 13; etc.
const CHAPTER_1 = 2; //2 for test purposes only.
//+-------------------------------------------------------+//
//| DON'T EDIT BELOW THIS LINE!!! |//
//+-------------------------------------------------------+//
//Defining this function for later. Thanks to an anon on php.net for this!
//This will allow me to get the constants with the $prefix prefix. In this
//case all the chapters will be defined with "CHAPTER_x" so using the prefix
//'CHAPTER' in the function will return all the chapter constants ONLY.
function returnConstants ($prefix) {
foreach (get_defined_constants() as $key=>$value) {
if (substr($key,0,strlen($prefix))==$prefix) {
$dump[$key] = $value;
}
}
if(empty($dump)) {
return "Error: No Constants found with prefix '" . $prefix . "'";
}
else {
return $dump;
}
}
//---------------------------------------------------------//
$archiveDir = "public_html/archive";
$files = array_diff(scandir($archiveDir), array("..", "."));
//This SHOULD populate the array in order, for example:
//$files[0]='20131125.png', $files[1]='20131126.png', etc.
//---------------------------------------------------------//
$pages = array();
foreach ($files as $file) {
//This parses through the files and takes only .png files to put in $pages.
$parts = pathinfo($file);
if ($parts['extension'] == "png") {
$pages[] = $file;
}
unset($parts);
}
//Now that we have our pages, let's assign the links to them.
$totalPages = count($pages);
$pageNums = array();
foreach ($pages as $page) {
//This will be used to populate the page numbers for the links.
//e.g. "<a href='archive.php?p=$pageNum'></a>"
for($i=1; $i<=$totalPages; $i++) {
$pageNums[] = $i;
}
//This SHOULD set the $pageNum array to be something like:
//$pageNum[0] = 1, $pageNum[1] = 2, etc.
}
$linkText = array();
$archiveLinks = array();
foreach ($pageNums as $pageNum) {
//This is going to cycle through each page number and
//check how to display them.
if ($totalPages < 10) {
$linkText[] = $pageNum;
}
elseif ($totalPages < 100) {
$linkText[] = "0" . $pageNum;
}
else {
$linkText[] = "00" . $pageNum;
}
}
//So, now we have the page numbers and the link text.
//Let's plug everything into a link array.
for ($i=0; $i<$totalPages; $i++) {
$archiveLinks[] = "<a href='archive.php?p=" . $pageNums[$i] . "'>" . $linkText[$i] . " " . "</a>";
//Should output: <a href= 'archive.php?p=1'>01 </a>
//as an example, of course.
}
//And now for the fun part. Let's take the links and display them.
//Making sure to automatically assign the pages to their respective chapters!
//I've tested the below using given values (instead of fetching stuff)
//and it worked fine. So I doubt this is causing it, but I kept it just in case.
$rawChapters = returnConstants('CHAPTER');
$chapters = array_values($rawChapters);
$totalChapters = count($chapters);
$chapterTitles = array();
for ($i=1; $i<=$totalChapters; $i++) {
$chapterTitles[] = "<h4>Chapter " . $i . ":</h4><p>";
echo $chapterTitles[($i-1)];
for ($j=1; $j<=$chapters[($i-1)]; $j++) {
echo array_shift($archiveLinks[($j-1)]);
}
echo "</p>"; //added to test if this was causing the deletion
}
?>
What is causing the remainder of the document to vanish like that? EDIT: Two silly syntax errors were causing this, and have been fixed in the above code! However, the links aren't being displayed at all? Please note that I am pretty new to php and I do not expect my code to be the most efficient (I just want the darn thing to work!).
Addendum: if you deem to rewrite the code (instead of simply fixing error(s)) to be the preferred course of action, please do explain what the code is doing, as I do not like using code I do not understand. Thanks!
Without having access to any of the rest of the code or data-structures I can see 2 syntax errors...
Line 45:
foreach ($pages = $page) {
Should be:
foreach ($pages as $page) {
Line 88:
echo array_shift($archiveLinks[($j-1)];
Is missing a bracket:
echo array_shift($archiveLinks[($j-1)]);
Important...
In order to ensure that you can find these kinds of errors yourself, you need to ensure that the error reporting is switched on to a level that means these get shown to you, or learn where your logs are and how to read them.
See the documentation on php.net here:
http://php.net/manual/en/function.error-reporting.php
IMO all development servers should have the highest level of error reporting switched on by default so that you never miss an error, warning or notice. It just makes your job a whole lot easier.
Documentation on setting up at runtime can be found here:
http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors
There is an error in scripts/autodir.php this file. Everything up to that point works fine, so this is where the problem starts.
Also you mostlikely have errors hidden as Chen Asraf mentioned, so turn on the errors:
error_reporting(E_ALL);
ini_set('display_errors', '1');
Just put that at the top of the php file.
My PHP code is:
<?php
class Sample{
public $name = "N3mo";
public $answer = "";
}
if( isset( $_GET['request'] ) ){
echo "Starting to read ";
$req = $_GET[ 'request' ];
$result = json_decode($req);
if( $result->request == "Sample" ){
$ans = new Sample();
$ans->answer = " It Is Working !!! ";
echo json_encode($ans);
}else{
echo "Not Supported";
}
}
?>
Is there anything wrong
I want to send a JSON to this php and read the JSON that it returns using java script , I can't figure out how to use JavaScript in this , because php creates an html file how Can I use $_getJson and functions like that to make this happen ?!
I tried using
$.getJSON('server.php',request={'request': 'Sample'}) )
but php can't read this input or it's wrong somehow
thank you
try this out. It uses jQuery to load contents output from a server URL
<!DOCTYPE html>
<html>
<head>
<title>AJAX Load Test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#button").click(function(event) {
$('#responce').load('php_code.php?request={"request":"Sample"}');
});
});
</script>
</head>
<body>
<p>Click on the button to load results from php_code.php:</p>
<div id="responce" style="background-color:yellow;padding:5px 15px">
Waiting...
</div>
<input type="button" id="button" value="Load Data" />
</body>
</html>
Code below is an amended version of your code. Store in a file called php_code.php, store in the same directory as the above and test away.
<?php
class Sample
{
public $name = "N3mo";
public $answer = "";
}
if( isset( $_GET['request'] ) )
{
echo "Starting to read ";
$req = $_GET['request'];
$result = json_decode($req);
if( isset($result->request) && $result->request == "Sample" )
{
$ans = new Sample();
$ans->answer = " It Is Working !!! ";
echo json_encode($ans);
}
else
{
echo "Not Supported";
}
}
Let me know how you get on
It would be as simple as:
$.getJSON('/path/to/php/server.php',
{request: JSON.stringify({request: 'Sample'})}).done(function (data) {
console.log(data);
});
You can either include this in <script> tags or in an included JavaScript file to use whenever you need it.
You're on the right path; PHP outputs a result and you use AJAX to get that result. When you view it in a browser, it'll naturally show you an HTML result due to your browser's interpretation of the JSON data.
To get that data into JavaScript, use jQuery.get():
$.get('output.html', function(data) {
var importedData = data;
console.log('Shiny daya: ' + importedData);
});
Hi so I'm trying to parse the ratemyprofessor website for professor name and comments and convert each div into plaintext. Here is the div class structure that I'm working with.
<div id="ratingTable">
<div class="ratingTableHeader"></div>
<div class="entry odd"><a name="18947089"></a>
<div class="date">
8/24/11 // the date which I want to parse
</div><div class="class"><p>
ENGL2323 // the class which I want to parse
</p></div><div class="rating"></div><div class="comment" style="width:350px;">
<!-- comment section -->
<p class="commentText"> // this is what I want to parse as plaintext for each entry
I have had Altimont for 4 classes. He is absolutely one of my favorite professors at St. Ed's. He's generous with his time, extremely knowledgeable, and such an all around great guy to know. Having class with him he would always have insightful comments on what we were reading, and he speaks with a lot of passion about literature. Just the best!
</p><div class="flagsIcons"></div></div>
<!-- closes comment -->
</div>
<!-- closes even or odd -->
<div class="entry even"></div> // these divs are the entries for each professor
<!-- closes even or odd -->
<div class="entry odd"></div>
<!-- closes even or odd -->
</div>
<!-- closes rating table -->
So every entry is encapsulated under this "ratingtable" div and each entry is either "entry odd" or "entry even" div.
Here is my attempt so far but it just produces a huge garbled array with a lot of garbage.
<?php
header('Content-type: text/html; charset=utf-8'); // this just makes sure encoding is right
include('simple_html_dom.php'); // the parser library
$html = file_get_html('http://www.ratemyprofessors.com/SelectTeacher.jsp?sid=834'); // the url for the teacher rating profile
//first attempt, rendered nothing though
foreach($html->find("div[class=commentText]") as $content){
echo $content.'<hr />';
}
foreach($html->find("div[class=commentText]") as $content){
$content = <div class="commentText"> // first_child() should be the <p>
echo $content->first_child().'<hr />';
//Get the <p>'s following the <div class="commentText">
$next = $content->next_sibling();
while ($next->tag == 'p') {
echo $next.'<hr />';
$next = $next->next_sibling();
}
}
?>
Confusing HTML... Could you try and see if this works?
foreach (DOM($html, '//div[#class="commentText"]//div[contains(#class,"entry")]') as $comment)
{
echo strval($comment);
}
Oh, and yeah - I don't like simple_html_dom, use this instead:
function DOM($html, $xpath = null, $key = null, $default = false)
{
if (is_string($html) === true)
{
$dom = new \DOMDocument();
if (libxml_use_internal_errors(true) === true)
{
libxml_clear_errors();
}
if (#$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8')) === true)
{
return DOM(simplexml_import_dom($dom), $xpath, $key, $default);
}
}
else if (is_object($html) === true)
{
if (isset($xpath) === true)
{
$html = $html->xpath($xpath);
}
if (isset($key) === true)
{
if (is_array($key) !== true)
{
$key = explode('.', $key);
}
foreach ((array) $key as $value)
{
$html = (is_object($html) === true) ? get_object_vars($html) : $html;
if ((is_array($html) !== true) || (array_key_exists($value, $html) !== true))
{
return $default;
}
$html = $html[$value];
}
}
return $html;
}
return false;
}
If you still want to use simple_html_dom.. see below code for the mistakes in your code:
<?php
header('Content-type: text/html; charset=utf-8'); // this just makes sure encoding is right
include('simple_html_dom.php'); // the parser library
// you were trying to parse the wrong link.. your previous link did not have <div> tag with commentText class .. I chose a random link.. choose link for whichever professor you like or grab the links of professor from previous page store it in an array and loopr through them to get comments
$html = file_get_html('http://www.ratemyprofessors.com/ShowRatings.jsp?tid=1398302'); // the url for the teacher rating profile
//first attempt, rendered nothing though
//your div tag has class "comment" not "commentText"
foreach($html->find("div[class=comment]") as $content){
echo $content.'<hr />';
}
foreach($html->find("div[class=comment]") as $content){
// I am not sure what you are trying to do here but watever it is it's wrong
//$content = <div class='commentText'>"; // first_child() should be the <p>
//echo $content->first_child().'<hr />';
//correct way to do it
echo $html->firstChild();// ->first_child().'<hr />';
//this whole code does not make any sense since you are already retrieving the comments from the above code.. but if you still want to use it .. I can figure out what to do
//Get the <p>'s following the <div class="commentText">
// $next = $html->firstChild()->next_sibling();
// while ($next->tag == 'p') {
// echo $next.'<hr />';
// $next = $next->next_sibling();
// }
}
?>
Output
Comment
Dr.Alexander was the best. I would recommend him for American Experience or any class he teaches really. He is an amazing professor and one of the nicest most kind hearted people i've ever met.
Report this rating
Professor Alexander is SO great. I would recommend him to everyone for american experience. He has a huge heart and he's really interested in getting to know his students as actual people. The class isn't difficult and is super interesting. He's amazing.
Report this rating
Dins
Trying to make an auto directory lister with a download function for every subdirectory. I'd like to make these subdirectories available as .zip files to allow for easier downloading and to use less bandwith on the server.
The following script was working fine until I added the pclzip.lib and tried to let it create a zip file.
<html>
<head>
<?php require_once("pclzip.lib.php");?>
<?php require_once("filesize_lib.php"); ?>
<style type="text/css">
.readme{
width:500px;
height:150px;
background: silver;
overflow-x: hidden;
overflow-y: scroll;
}
</style>
</head>
<body>
<?php
$readme = "/readme.txt";
$download = "downloads";
// Openen
$dir = new DirectoryIterator('.');
// Doorlopen
?>
<table width="960px" border="1px"><tr><td width="185px"><strong>Name</strong></td><td width="50px"><strong>Type</strong></td><td width="50px"><strong>Size</strong></td><td width="125px"><strong>Last Modified</strong></td><td><strong>Short description</strong></td><td width="50px"><strong>Download</strong></td></tr>
<?php
foreach ($dir as $file)
{
if (! $file->isDot()
&& $file != ".."
&& $file != "index.php"
&& $file != "filesize_lib.php"
&& $file != "downloads"
)
{ ?><tr><td><?php
echo ''.$file.'';
?></td><td><?php
echo filetype($file);
?></td><td><?php
echo fileORdirSize($file).'<br/>';
?></td><td><?php
echo date("M j, Y", filemtime($file));
?></td><?php
if (filetype($file) == "dir"){
?>
<td><div class="readme"><?php
echo file_get_contents($file.$readme);
?></div></td><?php
} else {
?><td>Files don't have descriptions, but can be tested directly from this page.</td><?php
}
?><td><?php
$zip = new PclZip("tmp/archief.zip");
if($zip->create($file) == 0)
die("Error : " . $zip->errorInfo(true));
echo ''.$zip.'';
?></td></tr><?php
}
}
?>
</table>
</body>
</html>
The error I'm receiving is the following:
Invalid variable type p_filelist [code -3]
Which I believe is due to the fact that I'm feeding pclzip.lib a single variable and not an array. Unfortunately, I don't know how to solve this problem. See the piece of code that is responsible for the problem (according to me) below:
<?php // ----- Init
$v_string_list = array();
$v_att_list = array();
$v_filedescr_list = array();
$p_result_list = array();
// ----- Look if the $p_filelist is really an array
if (is_array($p_filelist)) {
// ----- Look if the first element is also an array
// This will mean that this is a file description entry
if (isset($p_filelist[0]) && is_array($p_filelist[0])) {
$v_att_list = $p_filelist;
}
// ----- The list is a list of string names
else {
$v_string_list = $p_filelist;
}
}
// ----- Look if the $p_filelist is a string
else if (is_string($p_filelist)) {
// ----- Create a list from the string
$v_string_list = explode(PCLZIP_SEPARATOR, $p_filelist);
}
// ----- Invalid variable type for $p_filelist
else {
PclZip::privErrorLog(PCLZIP_ERR_INVALID_PARAMETER, "Invalid variable type p_filelist");
return 0;
}?>
Try instantiating your zip class before the start of the loop, and using the add() method rather than the create() method, otherwise you'll just be overwriting each archive with the next.
If you want to add a whole series of files in a single call, then either method expects an array of files, or a comma-separated list of files.
Ensure that $file is cast to string before calling the create() or add() method, you're passing an object
Also ensure that you're passing $file including any directory reference, else PCLZip won't find the file
<?php } elseif($_SOMETHING == 1 && $_ANOTHER_THING == 2) { ?>
<?php $_NAME = urlencode($_NAME); ?>
<?php $_MGT_NAME = urlencode($_MGT_NAME); ?>
</div>
<?php } ?>
I am getting this error expected ';'
The horror. The horror.
Here's the actual error, in the onclick attribute value:
lpButtonCTTUrl = 'http:...Ad%20Source=somesite.com& ='+escape(document.location); imageUrl=<?php print "http://{$_SERVER['SITENAME']}/images/";?>&referrer
That is, there should be a +' instead of ; after the document.location inclusion, and there should be a closing quote after the imageURL inclusion, and referrer is in the wrong place (it should be just before the document.location inclusion.
It also has problems like the use of escape (never use escape. For URL-encoding you actually want encodeURLComponent); the unescaped ampersands all over the place; and the lack of HTML- and URL-encoding of values output from PHP, potentially causing cross-site scripting risks.
Writing a value inside a URL component inside a URL inside a JavaScript string literal inside an attribute value inside HTML is utter insanity so it's no surprise there are mistakes. Let's try to bring some maintainability to this madness. Break out the JavaScript and URL creation into separate steps where getting the escaping right is possible.
function urlencodearray($a) {
$o= array();
foreach ($a as $k=>$v)
array_push($o, rawurlencode($k).'='.rawurlencode($v));
return implode('&', $o);
}
function h($s) {
echo htmlspecialchars($s);
}
With these utility functions defined, then:
<?php } elseif($_SOMETHING == 1 && $_ANOTHER_THING == 2) { ?>
<?php
$lpbase= 'http://server.iad.liveperson.net/hc/84152841/?';
$linkurl= $lpbase.urlencodearray(array(
'cmd'=>'file',
'file'=>'visitorWantsToChat',
'site'=>'84152841',
'byhref'=>'1',
'skill'=>'somesiteILS',
'SESSIONVAR!skill'=>'somesiteILS',
'SESSIONVAR!Management Company'=>$_MGT_NAME,
'SESSIONVAR!Community'=>$_NAME,
'SESSIONVAR!Ad%20Source'=>'somesite.com',
'imageUrl'=>"http://{$_SERVER['SITENAME']}/images/"
));
$imgurl= $lpbase.urlencodearray(array(
'cmd'=>'repstate',
'site'=>'84152841',
'channel'=>'web',
'ver'=>'1',
'skill'=>'somesiteILS',
'imageUrl'=>"http://{$_SERVER['SITENAME']}/images/"
));
?>
<div id="caller_tag">
<a id="_lpChatBtn" target="chat84152841" href="<?php h($url); ?>">
<img src="<?php h($imgurl); ?>" name="hcIcon" alt="Chat" border="0">
</a>
<script type="text/javascript">
document.getElementById('_lpChatBtn').onclick= function() {
var url= this.href+'&referrer='+encodeURIComponent(location.href);
if ('lpAppendVisitorCookies' in window)
url= lpAppendVisitorCookies(url);
if ('lpMTag' in window && 'addFirstPartyCookies' in lpMTag)
url= lpMTag.addFirstPartyCookies(url)
window.open(url, this.target, 'width=475,height=400,resizable=yes');
return false;
};
</script>
</div>
With an unformatted mess like that it's no wonder you can't find the error.
I tried running it through HTML Tidy but it doesn't like anything between the comments.
mesite.com& ='+escape(document.location); imageUrl=<?php print "ht
I'm not good at reading long lines like that but shouldn't this be
mesite.com& ='+escape(document.location) +'imageUrl=<?php print "ht
First of: why are you opening and closing PHP so many times, you could write it like:
<?php
} elseif($_SOMETHING == 1 && $_ANOTHER_THING == 2) {
$_NAME = urlencode($_NAME);
$_MGT_NAME = urlencode($_MGT_NAME);
?>
<div id="caller_tag">
<!-- BEGIN LivePerson Button Code --><a id="_lpChatBtn" href='http://server.iad.liveperson.net/hc/84152841/?cmd=file&file=visitorWantsToChat&site=84152841&byhref=1&SESSIONVAR!skill=somesiteILS&SESSIONVAR!Management%20Company=<?php print $_MGT_NAME; ?>&SESSIONVAR!Community=<?php print $_NAME; ?>&SESSIONVAR!Ad%20Source=somesite.com&imageUrl=<?php print "http://{$_SERVER['SITENAME']}/images/";?>' target='chat84152841' onClick="lpButtonCTTUrl = 'http://server.iad.liveperson.net/hc/84152841/?cmd=file&file=visitorWantsToChat&site=84152841&SESSIONVAR!skill=somesiteILS&SESSIONVAR!Management%20Company=<?php print $_MGT_NAME; ?>&SESSIONVAR!Community=<?php print $_NAME; ?>&SESSIONVAR!Ad%20Source=somesite.com& ='+escape(document.location); imageUrl=<?php print "http://{$_SERVER['SITENAME']}/images/";?>&referrer lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);window.open(lpButtonCTTUrl,'chat84152841','width=475,height=400,resizable=yes');return false;" ><img src='http://server.iad.liveperson.net/hc/84152841/?cmd=repstate&site=84152841&channel=web&&ver=1&imageUrl=<?php print "http://{$_SERVER['SITENAME']}/images/";?>&skill=somesiteILS' name='hcIcon' alt='Chat Button' border=0></a><!-- END LivePerson Button code -->
</div>
And also: the error must be somewhere else, I can't see a missing ";" in php in the code you pasted, unless the error is in javascript.