Php to PB

Just starting out? Need help? Post your questions and find answers here.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Php to PB

Post by dagcrack »

Hello, I just wanted to know how difficult could it be to parse strings from a php page to a purebasic application (chat, using either page or pb appl as client) .. mysql backend ?, any examples that someone has made? . im so short in time that I must know an aproximate of time that could take to one person that is more or less advanced in pb and php to develop this.

thanks
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Oly
User
User
Posts: 15
Joined: Sat Aug 21, 2004 12:46 pm

Post by Oly »

I just posted a ASP - PHP Converter in the hints and tips forum with the code, this may be useful, you should be able to use the same principles to convert your php file into the required formaty although i am afraid the code is not commented.
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

Im afraid that I dont need a convertor, I need a way to parse strings via php to a pb application an vice versa, in realtime.
! Black holes are where God divided by zero !
My little blog!
(Not for the faint hearted!)
Oly
User
User
Posts: 15
Joined: Sat Aug 21, 2004 12:46 pm

Post by Oly »

I know you do not want a converter, but the program is a parser as it parses ASP code and convert it into PHP the parsing process can be used for any kind of parsing with modification.
The same principles could be applied to parse your php string into what ever format you require for PB, or if you just want the strings as is just do not convert them.
Effigy
User
User
Posts: 35
Joined: Fri Apr 25, 2003 5:40 pm
Location: Canada
Contact:

Post by Effigy »

I don't have an example, but one way to do this would be to use Network Sockets and XML in PHP and PB. That you could have communication to and from both languages.

This would be the easiest way to communicate between the programs.

Derek
Tommeh
Enthusiast
Enthusiast
Posts: 149
Joined: Sun Aug 29, 2004 2:25 pm
Location: United Kingdom

Post by Tommeh »

Ok i can help here, I think i know what you need.

The Php script you have, say its <? echo "hello" ?> write that to a temp file

When you have done that, Call php.exe with the parameter as the file name, Example: run php.exe c:\phptest.txt

Then via Stdout it will give you the result which will be hello, and there you have it :D
Effigy
User
User
Posts: 35
Joined: Fri Apr 25, 2003 5:40 pm
Location: Canada
Contact:

Post by Effigy »

Ok... I think I got something you can use....

This uses code borrowed from Num3's Fantastic Http1.1 Geturl library. You can find it here. viewtopic.php?t=11095&highlight=url+data

Anyway. Two Parts to this of course.

Part 1 PHP.

I just made a simple php page that takes Get variables through the URL and passes them back using echo.

Code: Select all

<?php 
if ($_GET['pbvar']<>""){
echo $_GET['pbvar'];
}
else {
echo "Hello World";
}
?>
Part 2 PB

So this part is more tricky, basically you have to Request the page Using the Http 1.1 Standard. I have left out all error checking code for simplicity sake. Although Num3 has many features including Cookies, Redirection and More.

Remeber this is just an example. Much more needs to be done.

PB Code.

Code: Select all

Procedure.s GetPhpVar(url$)

For a=1 To Len(url$) ;Get Server Value
    s_start=FindString(url$,"//",1) 
    s_end=FindString(url$,"/",s_start+2) 
    server$=Mid(url$,s_start+2,s_end-(s_start+2)) 
Next 

file$=ReplaceString(url$,"http://"+server$,"") ;Get File Value

port$="80"
ConnectionID = OpenNetworkConnection(server$, Val(port$)) 

If ConnectionID ;Compile Header for Request
    
    ;/// File Information 
    com$="GET "+file$+" HTTP/1.1"+Chr(13)+Chr(10) 
    com$+"Accept: */*"+Chr(13)+Chr(10) 
    com$+"Host: "+server$+Chr(13)+Chr(10) 
    com$+"User-Agent: PureDownload 1.0"+Chr(13)+Chr(10) 
    com$+Chr(13)+Chr(10) 
    res = SendNetworkData(ConnectionID,@com$,Len(com$)) 

EndIf
finished=#false
Repeat 
      Delay(10) 
      Result = NetworkClientEvent(ConnectionID) 
      If Result=2 ;/// Raw data received 
        finished=#true
        Content$ = Space(14500) 
        ReceiveNetworkData(ConnectionID,@Content$,14500) 
        
        Content$=Trim(Content$) 
        
        ;/// File not found handle 
        If FindString(Content$,"404",1) 
          CloseNetworkConnection(ConnectionID) 
        EndIf 
      EndIf 
        
      
    Until finished=#True 

;Clean out header and leave Content
;Headerlen=FindString(content$,Chr(13)+Chr(10)+Chr(13)+Chr(10),1)
Data1=FindString(content$,"<~",1)
data2=FindString(content$,"~>",1)
leftover.s=Mid(content$,data1+2,data2-data1-2)
;Leftover.s=Right(content$,Len(content$)-headerlen-3)
ProcedureReturn Leftover.s
EndProcedure


If InitNetwork()
myurl$="http://www.dynamicdot.ca/pb/hellow.php?pbvar=<~This%20came%20from%20PB.~>" 
;%20= "Space" the "<~ and ~> are markers so we know where the data is. It would be best to use XML for variable control.
Myphpvar.s=""
myphpvar.s=GetPhpVar(myurl$)
MessageRequester("Returned Value","The returned Value from the php script was: " + Chr(13) + myphpvar.s)
Endif
I posted the php on my site so you can freely use it for testing if you don't have a Webserver.

Hope this helps.
Derek Gavey
- PB Newbie -
Post Reply