Web Analytics Made Easy -
StatCounter T_CONSTANT_ENCAPSED_STRING error :( Help - CodingForum

Announcement

Collapse
No announcement yet.

T_CONSTANT_ENCAPSED_STRING error :( Help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • T_CONSTANT_ENCAPSED_STRING error :( Help

    I'm trying to stick in just a news feeder on the right side of my page but can't for the life of my figure out what I left out to cause this error. BTW Magic quotes is on

    <b>Parse error</b>: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in <b>/var/www/vhosts/thinkpost.com/httpdocs/library/app/universal.module.php(96) : eval()'d code</b> on line <b>1</b><br>


    Here is the code

    Code:
    function render_main_left_column() {
        global $db, $special, $happiness;
        print '
          <div class="right column">
            <div class="newsfeed">
              <div class="heading">
                <h3 class="title left">News & Entertainment</h3>
                <p class="right link01"><a href="'.url.'/mainrss" class="rss">Get RSS</a></p>
              </div>';
              $list_news = $db->query("select * from news order by time desc limit 10");
              $i = 0;
              $output2 = readfeed('http://news.google.com/news?ned=us&topic=e&output=rss');        
              $output1 = readfeed('http://news.google.com/nwshp?hl=en&tab=wn&q=&output=rss');   
              $q = array_merge($output1, $output2);
              $output3 = readfeed('http://my.abcnews.go.com/rsspublic/sports_rss20.xml');
              $q2 = array_merge(array_unique($q), $output3);     
    	      while($posts = $db->query_collection($list_news)) {
              	array_walk($posts, 'clean_for_reading');
              	$post[] = $posts;
              }
              foreach ($post as $item4) $q2[] = $item4;          
              $q2 = columnSort($q2, 'time');
    		  foreach (array_slice($q2, 0, 6) as $news) {
                array_walk($news, 'clean_for_reading');
                $newsid = $news['newsid'];
                $title = $news['title'];
                $url = $news['url'];
                $body = $news['body'];
                if (!$body) $body = $posts['body'];
                $date = format_date($news['time'], 'reading');
                $nobg = ($i == 0) ? ' nobg' : '' ;
                $i++;
              print '
              <div class="item'.$nobg.'">
                <h4>';
              if ($url) print '<a href="'.$url.'">'.$title.'</a></h4>';
              else print '<a href="'.$news['link'].'" target="blank">'.$title.'</a></h4>';
              print '
                <p>
                  '.shorten_text(publish(strip_tags($body)), 110).'
                </p>
                <div class="footer">
                  <p class="left"><span class="hide">Posted on: </span>'.$date.'</p>';
              	  if ($url) print '<p class="right circlearrow link02"><a href="/newspost/'.$newsid.'/'.clean_for_url($title).'">Read details</a></p>';
              	  else print '<p class="right circlearrow link02"><a href="'.$news['link'].'" target="blank">Read details</a></p>';
                 print '
                </div>
              </div>';
              }
              
              print '
                <div class="footer">
                  <p class="right circlearrow link02"><a href="'.url.'/news">More news</a></p>
                </div>
            </div>
    				
    				<div class="newsfeed">
    					<div class="heading">
    						<h3 class="title subtitle left">Sound Off</h3>
    					</div>
    					<div class="item nobg">';
    					global $soundoff, $active_user;
               $sounds = $db->query_single("select * from soundoffs order by time desc limit 1");
               $s = o($sounds);
               print '
    						<h4>'.$s->question.'</h4>';
    						$has_voted = $soundoff->has_voted($active_user, $s->soundoffid);
                if(!$has_voted and $active_user) {
                  print '
              <div id="response">
    						<form class="poll" id="soundoff-form" onsubmit="soundoff(); return false;">';
                  print '<input type="hidden" class="hide" name="soundoffid" value="'.$s->soundoffid.'" />
                  <ul class="radiogroup">
                  ';
                  if($s->choice1 != '') print '<li>
                      <span class="radio">
    							<input type="radio" name="vote" value="votes1_'.$s->choice1.'"/><label>'.$s->choice1.'</label></span>
                    </li>';
                  if($s->choice2 != '') print '<li>
                      <span class="radio">
    							<input type="radio" name="vote" value="votes2_'.$s->choice2.'"/><label>'.$s->choice2.'</label></span>
                    </li>';
                  if($s->choice3 != '') print '<li>
                      <span class="radio">
    							<input type="radio" name="vote" value="votes3_'.$s->choice3.'"/><label>'.$s->choice3.'</label></span>
                    </li>';
                  if($s->choice4 != '') print '<li>
                      <span class="radio">
    							<input type="radio" name="vote" value="votes4_'.$s->choice4.'"/><label>'.$s->choice4.'</label></span>
                    </li>';
                  if($s->choice5 != '') print '<li>
                      <span class="radio">
    							<input type="radio" name="vote" value="votes5_'.$s->choice5.'"/><label>'.$s->choice5.'</label></span>
                    </li>';
    							print '
    							</ul>
    							</p>
    							<textarea class="comments" name="comment"></textarea>
    							<input type="submit" class="button" value="Submit" />
    						</form>
               </div>';
    						} else if($has_voted && $active_user) {
    						  $voteid = $has_voted['voteid'];
    						  $comment = $has_voted['comment'];
    						  $vote = $has_voted['vote'];
    						  $answer = '<br/>Your Answer: '.$vote;
    						  if($comment) $answer .= '<br/>Your Comment: '.$comment;
                  print '<p>You have already voted'.$answer.'</p>';
                } else {
                  print '<p>Please <a href="http://www.thinkpost.com/login">login</a> or <a href="http://www.thinkpost.com/signup">sign-up</a> to vote.</p>';
                }
                print '
    					</div>
             
    					<div class="item no-border">';
    					  $num = ($s->num_votes == 0) ? 0 : $s->num_votes ;
    					  if($s->num_votes == 0) $s->num_votes = 1;
                if($s->choice1) print '
    						<span class="colour02">'.$s->choice1.' : </span> '.number_format(($s->votes1/$s->num_votes)*100).'%';
                if($s->choice2) print '
    						<br /><span class="colour02">'.$s->choice2.' : </span> '.number_format(($s->votes2/$s->num_votes)*100).'%';
                if($s->choice3) print '
    						<br /><span class="colour02">'.$s->choice3.' : </span> '.number_format(($s->votes3/$s->num_votes)*100).'%';
                if($s->choice4) print '
    						<br /><span class="colour02">'.$s->choice4.' : </span> '.number_format(($s->votes4/$s->num_votes)*100).'%';
                if($s->choice5) print '
    						<br /><span class="colour02">'.$s->choice5.' : </span> '.number_format(($s->votes5/$s->num_votes)*100).'%';
    						print '
    						<br/>Total votes: '.$num.'
    						<br/><a href="'.url.'/soundoffs">More Soundoffs</a>
    					</div>
    								
    				</div>				
    				';
            print '
          </div>
          </div>
          <hr />';
      }
    readfeed is
    Code:
     function readfeed($url){
    		$atom_parser = new AtomParser($url);
    		$output = $atom_parser->normalize();
    		if (!is_array($output)) $output = readrss($url);
    		return $output;
    	}
    and atom parser

    Code:
      function AtomParser($file)
        {
          $xml_parser = xml_parser_create("");
          xml_set_object($xml_parser, $this);
          xml_set_element_handler($xml_parser, "startElement", "endElement");
          xml_set_character_data_handler($xml_parser, "parseData");
    
          $fp = @fopen($file, "r");
          while($data = @fread($fp, 4096)) {
            xml_parse($xml_parser, $data, feof($fp)) or die(
              sprintf("myAtomParser: Error <b>%s</b> at line <b>%d</b><br>",
              xml_error_string(xml_get_error_code($xml_parser)),
              xml_get_current_line_number($xml_parser))
            );
          }
          @fclose($fp);
    
          xml_parser_free($xml_parser);
        }

  • #2
    You are showing us the code for universal.module.php?

    Comment


    • #3
      The first snippet of code isn't the universal module... I put in snippits of the functions it was calling in it in case it would help

      Comment


      • #4
        Can you post universal.module.php?

        Comment


        • #5
          Code:
          <?
          
            class AtomParser
            {
              var $tags = array();
          
              var $output = array();
              
              var $arr = array();
          
              function AtomParser($file)
              {
                $xml_parser = xml_parser_create("");
                xml_set_object($xml_parser, $this);
                xml_set_element_handler($xml_parser, "startElement", "endElement");
                xml_set_character_data_handler($xml_parser, "parseData");
          
                $fp = @fopen($file, "r");
                while($data = @fread($fp, 4096)) {
                  xml_parse($xml_parser, $data, feof($fp)) or die(
                    sprintf("myAtomParser: Error <b>%s</b> at line <b>%d</b><br>",
                    xml_error_string(xml_get_error_code($xml_parser)),
                    xml_get_current_line_number($xml_parser))
                  );
                }
                @fclose($fp);
          
                xml_parser_free($xml_parser);
              }
          
              function startElement($parser, $tagname, $attrs)
              {
                if($this->encoding) {
                  $tmpdata = "<$tagname";
                  if($attrs) foreach($attrs as $key => $val) $tmpdata .= " $key=\"$val\"";
                  $tmpdata .= ">";
                  $this->parseData($parser, $tmpdata);
                } else {
                  if($attrs['HREF'] && $attrs['REL'] && $attrs['REL'] == 'alternate') {
                    $this->startElement($parser, 'LINK', array());
                    $this->parseData($parser, $attrs['HREF']);
                    $this->endElement($parser, 'LINK');
                  }
                  if($attrs['TYPE']) $this->encoding[$tagname] = $attrs['TYPE'];
          
                  if(preg_match("/^(FEED|ENTRY)$/", $tagname)) {
                    if($this->tags) {
                      $depth = count($this->tags);
                      list($parent, $num) = each($tmp = end($this->tags));
                      if($parent) $this->tags[$depth-1][$parent][$tagname]++;
                    }
                    array_push($this->tags, array($tagname => array()));
                  } else {
                    array_push($this->tags, $tagname);
                  }
                }
              }
          
              function endElement($parser, $tagname)
              {
                if($this->encoding) {
                  if(isset($this->encoding[$tagname])) {
                    unset($this->encoding[$tagname]);
                    array_pop($this->tags);
                  } else {
                    if(!preg_match("/(BR|IMG)/", $tagname)) $this->parseData($parser, "</$tagname>");
                  }
                } else {
                  array_pop($this->tags);
                }
              }
          
              function parseData($parser, $data)
              {
                if(!trim($data)) return;
                $evalcode = "\$this->output";
                foreach($this->tags as $tag) {
                  if(is_array($tag)) {
                    list($tagname, $indexes) = each($tag);
                    $evalcode .= "[\"$tagname\"]";
                    if(${$tagname}) $evalcode .= "[" . (${$tagname} - 1) . "]";
                    if($indexes) extract($indexes);
                  } else {
                    if(preg_match("/^([A-Z]+):([A-Z]+)$/", $tag, $matches)) {
                      $evalcode .= "[\"$matches[1]\"][\"$matches[2]\"]";
                    } else {
                      $evalcode .= "[\"$tag\"]";
                    }
                  }
                }
          
                if(isset($this->encoding['CONTENT']) && $this->encoding['CONTENT'] == "text/plain") {
                  $data = "<pre>$data</pre>";
                }
          
                eval("$evalcode .= '" . addslashes($data) . "';");
              }
          
          
              
              function normalize(){
                $start_tag = key($this->output);    	
                switch($start_tag) {
                  case "FEED":
                    $i = 0;
                    foreach($this->output as $feed) 
                    	foreach ($feed['ENTRY'] as $entry) {
          	          	$this->arr[$i]['title'] = $entry['TITLE'];
          	          	$this->arr[$i]['body'] = stripcslashes($entry['CONTENT']);
          	          	$this->arr[$i]['link'] = $entry['LINK'];
          	          	$this->arr[$i]['date'] = date('m/d/Y', strtotime(substr_replace($entry['UPDATED'], '', 18)));
          	          	$this->arr[$i]['month'] = date('M' , strtotime(substr_replace($entry['UPDATED'], '', 18)));
          	          	$this->arr[$i]['year'] = date('Y' , strtotime(substr_replace($entry['UPDATED'], '', 18)));
          	          	$this->arr[$i]['time'] = strtotime(substr_replace($entry['UPDATED'], '', 18));
                    		$i++;
                    	}
                    return $this->arr;	
                    break;
                  default:
                    return  "Error: unrecognized start tag '$start_tag' in getOutput()";
                }    	
              }
          }
            
          $rss_channel = array();
          $currently_writing = "";
          $main = "";
          $item_counter = 0;
          
          function startElement($parser, $name, $attrs) {
             	global $rss_channel, $currently_writing, $main;
             	switch($name) {
             		case "RSS":
             		case "RDF:RDF":
             		case "ITEMS":
             			$currently_writing = "";
             			break;
             		case "CHANNEL":
             			$main = "CHANNEL";
             			break;
             		case "IMAGE":
             			$main = "IMAGE";
             			$rss_channel["IMAGE"] = array();
             			break;
             		case "ITEM":
             			$main = "ITEMS";
             			break;
             		default:
             			$currently_writing = $name;
             			break;
             	}
          }
          	
          function endElement($parser, $name) {
          	   	global $rss_channel, $currently_writing, $item_counter;
          	   	$currently_writing = "";
          	   	if ($name == "ITEM") {
          	   		$item_counter++;
          	   	}
          	}
          	
          function characterData($parser, $data) {
          		global $rss_channel, $currently_writing, $main, $item_counter;
          		if ($currently_writing != "") {
          			switch($main) {
          				case "CHANNEL":
          					if (isset($rss_channel[$currently_writing])) {
          						$rss_channel[$currently_writing] .= $data;
          					} else {
          						$rss_channel[$currently_writing] = $data;
          					}
          					break;
          				case "IMAGE":
          					if (isset($rss_channel[$main][$currently_writing])) {
          						$rss_channel[$main][$currently_writing] .= $data;
          					} else {
          						$rss_channel[$main][$currently_writing] = $data;
          					}
          					break;
          				case "ITEMS":
          					if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
          						$rss_channel[$main][$item_counter][$currently_writing] .= $data;
          					} else {
          						$rss_channel[$main][$item_counter][$currently_writing] = $data;
          					}
          					break;
          			}
          		}
          	}
          	
          	
          	$rss_channel = array();
          	$currently_writing = "";
          	$main = "";
          	$item_counter = 0;
          	
          function readrss($file){
          		global $rss_channel;
          		
          		$xml_parser = xml_parser_create();
          		xml_set_element_handler($xml_parser, "startElement", "endElement");
          		xml_set_character_data_handler($xml_parser, "characterData");
          		if (!($fp = @fopen($file, "r"))) {
          		}
          	
          		while ($data = @fread($fp, 4096)) {
          			if (!xml_parse($xml_parser, $data, feof($fp))) {
          				die(sprintf("XML error: %s at line %d",
          						xml_error_string(xml_get_error_code($xml_parser)),
          						xml_get_current_line_number($xml_parser)));
          			}
          		}
          		xml_parser_free($xml_parser);
          		
          		return normalize($rss_channel);
          	}
          	
          function normalize($channel){
          		  $i = 0;
          		  if (is_array($channel['ITEMS']))
          	      foreach($channel['ITEMS'] as $item) {
          	          	$arr[$i]['title'] = $item['TITLE'];
          	          	$arr[$i]['body'] = stripcslashes($item['DESCRIPTION']);
          	          	$arr[$i]['link'] = $item['LINK'];
          	          	$arr[$i]['date'] = date('m/d/Y', strtotime($item['PUBDATE']));
          	          	$arr[$i]['month'] = date('M' , strtotime($item['PUBDATE']));
          	          	$arr[$i]['year'] = date('Y' , strtotime($item['PUBDATE']));
          				$arr[$i]['time'] = strtotime($item['PUBDATE']);	          	
          	      		$i++;
          	      	}
          	      return $arr;		
          	}
          	
          function readfeed($url){
          		$atom_parser = new AtomParser($url);
          		$output = $atom_parser->normalize();
          		if (!is_array($output)) $output = readrss($url);
          		return $output;
          	}
          
          function columnSort($unsorted, $column) {
          $sorted = $unsorted;
          for ($i=0; $i < sizeof($sorted)-1; $i++) {
           for ($j=0; $j<sizeof($sorted)-1-$i; $j++)
             if ($sorted[$j][$column] < $sorted[$j+1][$column]) {
               $tmp = $sorted[$j];
               $sorted[$j] = $sorted[$j+1];
               $sorted[$j+1] = $tmp;
           }
          }
          return $sorted;
          }
          	
            function relocate($location) {
              header('location: '.$location);
            }
            
            function relocate_to_error() {
              header('location: /'.local.'error');
            }
            
            function user_home($username) {
              return 'http://www.thinkpost.com/home/'.$username;
            }
            
            function retrieve_id_from_uri($num = 2) {
              global $uri;
              $fragments = explode('/', $uri);
              return $fragments[$num];
            }
            
            function is_url($url) {
              global $uri;
              return (substr($uri, 0, strlen($url)) == $url);
            }
            
            function relocate_to_www() {
              global $absolute_url, $uri;
              $fragments = explode('.', $absolute_url);
              if($fragments[0] == protocol.system_alias) relocate(url.$uri);
            }
            
            function is_absolute_url($url) {
              global $absolute_url;
              return (substr($absolute_url, 0, strlen($url)) == $url);
            }
          ?>

          Comment


          • #6
            Well lemme explain the error to you, and maybe you can find the problem because the code you keep posting isn't the right code.

            <b>Parse error</b>: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in <b>/var/www/vhosts/thinkpost.com/httpdocs/library/app/universal.module.php(96) : eval()'d code</b> on line <b>1</b><br>
            You have an unexpected constant-encapsed-string in LINE 1 of the file /var/www/vhosts/thinkpost.com/httpdocs/library/app/universal.module.php. A constant-encapsed-string is just a string enclosed in single or double quotes. So look in /var/www/vhosts/thinkpost.com/httpdocs/library/app/universal.module.php, go to line 1, and check it out. Do you see a string in quotes? It is unexpected. Shouldn't be where it is.

            http://us3.php.net/manual/en/tokens.php

            Comment


            • #7
              Hey Fumigator,

              Thanks a lot with keeping up with me on this problem.

              The 3rd post I made is the exact code that is contained in the universal module.
              Basically this error is showing up on my rss newsfeed. I added the other code to show functions it references.

              Thanks again

              Comment

              Working...
              X