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
Php to PB
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.
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.
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
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

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.
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.
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.
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";
}
?>
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
Hope this helps.
Derek Gavey
- PB Newbie -
- PB Newbie -