0

Hi all, I have three inputs required at a prompt in the index file below which requires the following data a number which will be the title code such as tt0892318 and a number that will be prefixed with tt and be interpreted as the title code such as 0892318 and http://www.imdb.com/title/tt0892318. The problem I have is that the 0892318 is always returned as an empty string. Test have shown that the split string function is working and sends the correct data but returns empty.

If anyone can assist with this I would appreciate it.


Thanks in advance

David

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Movies</title>


</head>

<body>
<form action = 'current.php' method='post'>
Input Movie <input type='text' name='title' />
<input type='submit' name='submit' value='Submit' />
</form>

</body>
</html>
<?php

if (isset($_POST['submit'])){
   $title = $_POST['title'];
  
 
   //Here I'm spliting the title variable to see what the first two letter are
   $titleSplit = str_split($title, 2);
 
   if($titleSplit[0] == 'tt'){
      $url = 'http://www.imdb.com/title/' . $title;
	  $title = $url;
   }
   elseif($titleSplit[0] == 'ht' ){
      $url = $title;
	  $title = $url;
   }else{
      $url = 'http://www/imdb.com/title/tt' . $title;
	  $title = $url;
   } 

}


/// Extracting the title 
$some_link = $url;
//echo $some_link;// test variable output
//echo $url;// test variable output


$tagName = 'h1';
$attrName = 'class';
$attrValue = 'header';
 
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($title);// Getting information
 
$html = getTitle($dom, $tagName, $attrName, $attrValue);

if (!$html)// checking string is empty
{
	echo 'Incomplete Data, Redirecting...';
			Redirect("error.html");
}
 
/**
 * JavaScript Redirect Function - Redirects the user should the result data be empty
 * @param string $url the dynamic url to redirect to
 */
function Redirect($url) 
{ ?>
	<script type="text/javascript">
		window.location = "<?php echo $url ?>"
	</script>
<?php 
}
$i=0;
	while(isset($html[$i]))
	{
		$header = $html[$i];
 		echo $header;
		$take = preg_split("/\ /", $html[$i]);
// echo $take;
		for($n=0;$n<count($take);$n++)
		{ 
			//print($take[$n]);
			
		}		
		$i++;
	}
	echo "<br/>";
function getTitle($dom, $tagName, $attrName, $attrValue)
{
    	$html = '';
    	$domxpath = new DOMXPath($dom);
    	$newDom = new DOMDocument;
    	$newDom->formatOutput = true;
 
	$filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
 
    	$i = 0;
   	$x = 0;
    	while( $myItem = $filtered->item($i++) )
	{		
		$html[$x] = $filtered->item($x)->nodeValue ."<br>";
    		$x++;
	}
    	return $html;
 
}
// Extract ratings
$tagName = 'span';
$attrName = 'id';
$attrValue = 'star-bar-user-rate';
$subtag = 'b';
 
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($title);
 
$html = getRatings($dom, $tagName, $attrName, $attrValue);
 
	$i=0;
	while(isset($html[$i]))
	{
		echo "Viewer Ratings:"."&nbsp;",$html[$i];
 
 
		$i++;
	}
echo "<br/>";
function getRatings($dom, $tagName, $attrName, $attrValue)
{
	
    	$html = '';
    	$domxpath = new DOMXPath($dom);
    	$newDom = new DOMDocument;
    	$newDom->formatOutput = true;
 
	$filtered = $domxpath->query("//$tagName" . '[@' . $attrName . "='$attrValue']");
 
    	$i = 0;
   	$x = 0;
    	while( $myItem = $filtered->item($i++) )
	{		
		$html[$x] = $filtered->item($x)->nodeValue ."<br>";
    		$x++;
	}
    	return $html;
 
}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by davidjennings
0

Does it only return an empty string when you use numbers or does it return an empty string for all inputs?

0

Hi again, The string only returns an empty string on the tt+ number & numbers. then I added this line ( $title = $url;) and everything worked except the numbers?.

Thanks again

David

This topic has been dead for over six months. 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.