Results 1 to 6 of 6

Thread: Do you have access to php vars outside the tags ?

  1. #1

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Do you have access to php vars outside the tags ?

    If i 'GET' some incoming vars i want to parse the incoming data with VBscript,
    for ex,

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 

    <html lang="en"> 

        <body> 

    <?php     
             
        $u
    $HTTP_GET_VARS['p'];

    ?>

    <script type="text/vbscript">

    Const fsoForWriting = 2

    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("myXML.xml", fsoForWriting, True)

    'Write Data
    objTextStream.WriteLine "<?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "ISO-8859-1" & chr(34) & "?>"
    objTextStream.WriteLine "<table>"
    objTextStream.WriteLine "     <ID>" & u & "</FriendID>"
    objTextStream.WriteLine "</table>"

    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing

    </script> 

     </body> 
    </html>
    Isn't giving me any errors but not producing the XML file, also as i said in the title, how do i access the u variables outside the php tags ?

    If i put as msgbox u in the VBscript, its empty ?

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Do you ave access to php vars outside the tags ?

    becareful when printing out XML from php because PHP will parse the <? ?> tags as PHP and not ignore them as you want it to. To get around this just split them up in your code.

    As for accessing "u" from outside the php tags, this cant be done, if you want to use a variable from PHP you need to include it inside <? ?> tags. Printing out variable from php is easy so you dont need to worry, it can simply be done like this <?=$variable?>

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">

        <body>

    <?php     
             
        $u
    $HTTP_GET_VARS['p'];

    ?>

    <script type="text/vbscript">

    Const fsoForWriting = 2

    Dim objFSO
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'Open the text file
    Dim objTextStream
    Set objTextStream = objFSO.OpenTextFile("myXML.xml", fsoForWriting, True)

    'Write Data
    objTextStream.WriteLine "<" & "?xml version=" & chr(34) & "1.0" & chr(34) & " encoding=" & chr(34) & "ISO-8859-1" & chr(34) & "?" & ">"
    objTextStream.WriteLine "<table>"
    objTextStream.WriteLine "     <ID><?=$u?></FriendID>"
    objTextStream.WriteLine "</table>"

    'Close the file and clean up
    objTextStream.Close
    Set objTextStream = Nothing
    Set objFSO = Nothing

    </script>

    </body>
    </html>
    Edit:

    Just looking at your VBscript what are you trying to do? You cant write files to the clients computer? You can only write cookies.
    Last edited by john tindell; Feb 27th, 2006 at 03:12 PM.

  3. #3

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Do you ave access to php vars outside the tags ?

    Ok bit of a newb at this php, i will have incoming data and want to basically output that data to an XML file and thought i could do it using VBscript FILE I/O inside a php file.

    Dont even know if you can do this was just assuming you could.

    Its not getting past,

    VB Code:
    1. Set objTextStream = objFSO.OpenTextFile("myXML.xml", fsoForWriting, True)

    Any ideas?

    Your answer to the variable works great, thanks!

    I know i could do this via php but would rather use vbscript if i can get away with it.

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Do you have access to php vars outside the tags ?

    Your PHP code is fine but the problem is the VBScript. This runs on the client, since you cannot write file to the clients computer this is why the script is stopping.

    If you want to store values on the users computer then i suggest that you use cookies

    look at http://www.php.net/setcookie

    Gives a good intro into using cookies

  5. #5

    Thread Starter
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959

    Re: Do you have access to php vars outside the tags ?

    Will do it in php.

    To write an xml file you need tags that encapsulate all your sub cats like

    <start>
    <name></name>
    <date></date>
    <name></name>
    <date></date>
    </start>

    talking about the <start> and </start> tags.

    So for every new incoming data i have to write an end tag </start> well i need to remove that an readd it onto the end for each write to the xml file, i thought this would work but no luck,


    PHP Code:
      $read $read."<HEAD>"."\r\n";
       
    $read $read."     <name>".$a."</name>"."\r\n";
       
    $read $read."     <Time-Date>".$b."</Time-Date>"."\r\n";   
       
    $read $read."     <Refs>".$c."</Refs>"."\r\n";
       
    $read $read."</HEAD>"."\r\n";


       
    $rTag str_replace("</START>"""$read);
       
    $rTag $rTag."</START>";
       
    fwrite($fh$rTag."\r\n"); 

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Do you have access to php vars outside the tags ?

    There is a speical extension which has been written for parsing and editing XML files:

    http://www.php.net/domxml
    http://www.php.net/dom <-- PHP 5
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width