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;
 
}

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.