Current location: Hot Scripts Forums » Programming Languages » PHP » PHP in Html format is not working?


PHP in Html format is not working?

Reply
  #1 (permalink)  
Old 08-24-06, 12:07 AM
mohit's Avatar
mohit mohit is offline
Newbie Coder
 
Join Date: Jul 2006
Location: India
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
PHP in Html format is not working?

hi friends..

i used this code then it is working properly
Code:
<head>
<meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="/us_constitution/uscon.css">
<title>xyz:<?php echo $stringData; ?></title>
</head>
that means it is showing colors too.
but when i used this code like this
Code:
<meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>/uscon.css">
<title>xyz:<?php echo $stringData; ?></title>
</head>
where $base_url="/us_constitution";

but this is not showing that color..

i'm not getting where it is wrong while the same thing was working in perl.
Reply With Quote
  #2 (permalink)  
Old 08-24-06, 12:20 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
When you do a "view source" in a browser, does the second version show the proper contents?
__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Reply With Quote
  #3 (permalink)  
Old 08-24-06, 12:39 AM
mohit's Avatar
mohit mohit is offline
Newbie Coder
 
Join Date: Jul 2006
Location: India
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
ok..you check this code my php script..
PHP Code:

<html>

<?php
$stringData
=$_GET['q'];
$stringval=$_GET['offset'];

/*$stringData='' unless defined $stringData;
$stringval=0 unless defined $stringval;*/
// outputs the username that owns the running php/httpd process
// (on a system with the "search" executable in the path)
//exec("\"search.exe" $stringData $stringval\"&2>1);


$base_urlget_value_of('BaseUrl');
function 
get_value_of($name)
{
     
$lines file('config.txt');

     foreach (
array_values($lines) AS $line)
     {
          list(
$key$val) = explode('='trim($line) );

          if (
trim($key) == $name)
          {
                return 
trim($val);
          }
     }
     return 
false;
}

?>

<head>
<meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="/us_constitution/uscon.css">
<title>xyz:<?php echo $stringData?></title>
</head>

<body>

<div id="navigation">
<form id="usconSearch" action="">
<strong>
Search the <a href="/<?php echo $base_url?>/index.html">US Constitution</a>:
</strong>
<input type="text" name="q" id="q" value="<?php echo $stringData?>">
<input type="submit" value="Search">
<input type="hidden" name="offset" value="0">
</form>
</div><!--navigation-->

<div id="bodytext">
<?php

exec
('search.exe amendment 10',$result);
echo 
$result[0];
?>

<p style="font-size: smaller; color: #666">
<em>Powered by
<a href="/xyz/Index.html">
powered by xyz
</a>
</em>
</p>
</div><!--bodytext-->

</body>

</html>
when i call this script first time it shows a search age like google.
. with consider the above problem at that time i was not talking about content. now you can understand better to view this code and first post problem...

and both version showing first page with proper content but difference of only color. one is showing other is not showing...

let me know if you need more info

Last edited by nico_swd; 08-24-06 at 02:13 AM.
Reply With Quote
  #4 (permalink)  
Old 08-24-06, 03:48 AM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
Well your code is certainly interesting...

First of all are you aware of the $_SERVER['SEVER_NAME'] and $_SERVER['DOCUMENT_ROOT'] variables in php? if not I would recommend reading up on php.net about them.

Secondly your get_value_of function is adding a ton of additional overhead that you could of just got away with declaring constants or variables in an include file and including it via include('filename.php');

Lastly I believe your best bet is to do a var_dump or echo on the variable before your html head block and after and see what is happening to that variable. I would also recommend fully-qualifing i.e. http://servername.tld/path/to/file the href as well, there could be something going on internally.
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Reply With Quote
  #5 (permalink)  
Old 08-24-06, 05:08 AM
mohit's Avatar
mohit mohit is offline
Newbie Coder
 
Join Date: Jul 2006
Location: India
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
hi infinitylimit

plz have look at this

http://www.rectangular.com/cgi-bin/uscon_search.cgi

i'm going to create this using kinosearch.i made a exe which use kinosearch and return values...in it' tutorial there is given a script in perl so i'm going to handle it's html part in php. so my exe return this
Code:
<main>
<Result> 
<abc>"some text her"</abc>
<xyz>"some value"</xyz>
</Result>
<Result> 
<abc>"some text her"</abc>
<xyz>"some value"</xyz>
</Result>
<Result> 
<abc>"some text her"</abc>
<xyz>"some value"</xyz>
</Result>
<qry>""</qry>
<url>""</url>
</main>
so i need to parse this into html an want to show result like this

http://www.rectangular.com/cgi-bin/u...ution&offset=0

but i'm first time working in php so i getting trouble...

now i have posted complete code..here..let me know what to do..


Thanks
Reply With Quote
  #6 (permalink)  
Old 08-26-06, 02:13 AM
mohit's Avatar
mohit mohit is offline
Newbie Coder
 
Join Date: Jul 2006
Location: India
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
hi,

i have solve the problem to read xml in php....
for that i used DOM object. it worked fine.
but after reading via it i want to convert my xml in html formatting.
the following code is just reading value from xml and converting into html.

but this is not showing the value and taking all object as string
PHP Code:

<?php

$output 
'<?xml version="1.0" encoding="ISO-8859-1"?>';
$output .='<?xml-stylesheet type="text/css" href="my_css.css"?>';
$output .= shell_exec("search.pl $stringData $stringval");
//exec('search.exe "$stringData" "$stringval"',$output);
//echo $output;
$dom=new DOMDocument();
$dom->LoadXML($output);
$root $dom->documentElement;
//echo $root->nodeName;
$report='';
if (
$root->hasChildNodes())
{
 
$children $root->childNodes;
     foreach(
$children as $node)
     {
          
          
//print $node->nodeName."\n";
          
if ($node->nodeName=="Result")
          {
               if (
$node->hasChildNodes())
               {
                    
$element=$dom->getElementsByTagName("Result");
                    
$length $element->length;
                    if(
$length>1)
                    {
                        
$report .= '<p>
                         <a href="$element->item(URL)->nodeValue"><strong>$element->item(Title)->nodeValue</strong></a>
                         <em>$element->item(Score)->nodeValue</em>
                         <br>
                         $element->item(BodyText)->nodeValue
                         <br>
                         <span class=excerptURL>$element->item(URL)->nodeValue</span></p>'
;
                         print 
$report;
                    }
                    else
                    {
                       
$report .="<p>$node->nodeValue</p>";
                   print 
$report;  
                    }
                   
               }
               
          }
          else
          {}
        
     }
}
?>
where xml is
PHP Code:

<main>

<
Result
<
Title>"some text her"</Title>
<
BodyText>"some value"</BodyText>
<
URL>""</URL>
</
Result>
<
Result
<
Title>"some text her"</Title>
<
BodyText>"some value"</BodyText>
<
URL>""</URL>
</
Result>
<
qry>""</qry>
<
url>""</url>
</
main
and i'm getting out put
PHP Code:

  <p> <a href="$element->item(URL)->nodeValue"><strong>$element->item(Title)->nodeValue</strong></a>

                         <
em>$element->item(Score)->nodeValue</em>
                         <
br>
                         
$element->item(BodyText)->nodeValue
                         
<br>
                         <
span class=excerptURL>$element->item(URL)->nodeValue</span></p
Reply With Quote
  #7 (permalink)  
Old 08-29-06, 03:24 AM
mohit's Avatar
mohit mohit is offline
Newbie Coder
 
Join Date: Jul 2006
Location: India
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
I have done it and it is working now absolutly fine..

Thanks to you all to kept replying me and helped me..


Thanks
Mohit
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I insert PHP code into HTML ?? cc79 HTML/XHTML/XML 5 04-12-08 11:00 AM
PHP to generate HTML as loaded from client side mgscom PHP 2 01-14-06 12:02 AM
Accessing PHP array in HTML to make radio buttons Newbie2005 PHP 35 10-20-05 01:32 PM
Php Html phppick PHP 2 12-09-04 08:27 PM
PHP to calculate HTML forms jamesian PHP 1 10-25-04 07:45 AM


All times are GMT -5. The time now is 07:26 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.