A Conversation for inject2g2

Buggy Code

Post 1

Pastey

Okay, here you go... I've spun this about and got this result. This script is written in PHP and uses the filesystem properties. It links into Betsie and uses it's text only version of the Guide to process, cutting down the work tremendously. It's more than a little buggy at the moment. It doesn't seem to let you log in yet, so I've no idea about whether or not it'll let you post anything or not. Also it's currently only outputting the html, but hey, it's commented as to where to change things, and as to what it's doing. It'll probably be about a week before I get another chance to play around with this, so I'll put it here and let someone else have a fiddle... \n"; $fileLink = $link; $file = fopen ("$fileLink", "r"); if (!$file) { echo "

Unable to hook into Betise.\n"; exit; } $page = ""; // there are 78 lines of bbc stuff at the top that we can bypass // so let us bypass them $currLine = 0; while (!feof ($file)) { $line = fgets ($file, 1024); if ($currLine > 78) { $page .= $line; } $currLine++; } fclose($file); /* now here is where you set it up to replace the html browser based stuff with code that is more suited to a Wap Browser. */ $header = "inject2g2"; $header .= ""; // do string replace tags for the page to make it wapable. $page = str_replace(' hope someone get's some time to play with this.


Buggy Code

Post 2

Pastey

Oops, better put in the version that probably won't get moderated out for broken links... NOTE TO MODERATORS: This is just a bit of code listing, the links aren't supposed to work, they're not links, they don't go anywhere, at least not intentionally. It's not my fault if anything that has http:// in it is considered a link, these aren't links, please don't mod them out. thanks. I've spun this about and got this result. This script is written in PHP and uses the filesystem properties. It links into Betsie and uses it's text only version of the Guide to process, cutting down the work tremendously. It's more than a little buggy at the moment. It doesn't seem to let you log in yet, so I've no idea about whether or not it'll let you post anything or not. Also it's currently only outputting the html, but hey, it's commented as to where to change things, and as to what it's doing. It'll probably be about a week before I get another chance to play around with this, so I'll put it here and let someone else have a fiddle... \n"; $fileLink = $link; $file = fopen ("$fileLink", "r"); if (!$file) { echo "

Unable to hook into Betise.\n"; exit; } $page = ""; // there are 78 lines of bbc stuff at the top that we can bypass // so let us bypass them $currLine = 0; while (!feof ($file)) { $line = fgets ($file, 1024); if ($currLine > 78) { $page .= $line; } $currLine++; } fclose($file); /* now here is where you set it up to replace the html browser based stuff with code that is more suited to a Wap Browser. */ $header = "inject2g2"; $header .= ""; // do string replace tags for the page to make it wapable. $page = str_replace(' hope someone get's some time to play with this.


Buggy Code

Post 3

Peregrin

Cool, looks good. I'm at work at the moment so I can't really have a play with it, but I will do when I get home smiley - smileysmiley - footprints


Buggy Code

Post 4

Pastey

Don't you just hate working?

smiley - rose


Buggy Code

Post 5

Peregrin

Yup smiley - winkeye I've got an opportunity to go freelance, which is highly tempting...

I didn't realise Betsie *could* handle h2g2, actually... cos I tried it before and it wouldn't work. It works quite well now.

I can use h2g2 on my mobile device using the usual HTML or now using Betsie. The latter is preferable in terms of bandwidth but what I'd really like to do it process the original HTML, not through Betsie, so I can leave small images in like the smileys and reply button.

I'll have a better look at the code later; I usually work in ASP, which doesn't have a way of requesting the pages (unless you use ASP.NET or some other component), so I'm not that familiar with PHP. But PHP looks far more suitable for this.


Buggy Code

Post 6

Pastey

Well you know where I am if you want to shout for PHP help. It's dead easy to do, especially if you already know ASP.

Parsing the html to leave in smilies would look better, but the processing/download time would go right up.

smiley - rose


Buggy Code

Post 7

Peregrin

OK I've had a play with your code, and it seems to me that I either need to 1) Learn PHP, or 2) Find a way of reading files from other domains with ASP.

Bah. smiley - erm

I think the former would be easier, annoyingly. Alternatively I could figure out a way of requesting the file from a PHP page and passing it on to an ASP page, but that's just smiley - silly.

Your code does most of the technical stuff (I'm surprised how easy it is with PHP); what I want to do next is to write a parser. I know how to do it theoretically, but I don't know to do it with the PHP language smiley - sadface

Can you recommend anywhere I can read up on PHP? I just need to know some string managing commands, really. Just replacing the basic links isn't really enough to be able to do everything from a mobile device - links are written in different ways, with different attributes (using text, images, forms, etc) and so the PHP str_replace command isn't really enough (for example, it couldn't remove all images, as the image tags all have unique attributes).


Buggy Code

Post 8

Pastey

http://www.php.net has an excellant documentation section, especially http://www.php.net/manual/en/ref.strings.php which goes into details about the string functions.
Using http://www.php.net/manual/en/function.strpos.php to find an occurance of a link in a line, it returns false if it's not there, and then using http://www.php.net/manual/en/function.str-replace.php to fiddle around could well be the way to do it.
If you know what the style of the pages that you're opening are, and you would using Betsie, then you know what text strings to look for to replace.

http://www.zend.com isn't too bad, but I'd stick with php.net. If you can't find what you're looking for, just asksmiley - smiley

smiley - rose


Buggy Code

Post 9

Peregrin

Cheers, that's great. smiley - cheers


Key: Complain about this post

Buggy Code

Write an Entry

"The Hitchhiker's Guide to the Galaxy is a wholly remarkable book. It has been compiled and recompiled many times and under many different editorships. It contains contributions from countless numbers of travellers and researchers."

Write an entry
Read more