Jump to content

Aeternus

Senior Members
  • Posts

    349
  • Joined

  • Last visited

Posts posted by Aeternus

  1. Pangloss, i think alot of people suggest C/C++ as a starting language as, although they're hard to start, they teach you the fundamentals and don't do very much for you (ie memory management, pointers etc). Some people don't like this but it prevents you getting the wrong idea about how a computer does something.

     

    There are alot of programmers now days who learnt their trade from the higher level languages (not "high" as C/C++ are high level) and they are often worse programmers because of it as they simply dont know the computational cost of what they are doing as most of the time there are alot of functions and methods that will do it for them and they will use without taking the time to consider whether that function will use alot of resources etc. There are even articles that suggest you should start yourself off on assembler/assembly, so that you really have a good idea of what is going on behind the scenes before you start having it all done for you, although that might be a little extreme for some.

     

    I'm not saying I suggest that they learn C/C++ or any other language, I think they'll be ok whatever language they choose (ok maybe not ANY but whatever), just pointing out why some might advocate C/C++ or similar.

  2.  $article_text = preg_replace("#\[url=([^(?:javascript)][^\[]+)\]([^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\2</a>", $article_text);
    $article_text = preg_replace("#\[url\]([^(?:javascript:)][^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\1</a>", $article_text);

     

    Seems you simply needed to include the delimiters at the beginning and end of the regex pattern, and the 'i' modifier to ensure case sensitivity.

     

    One thing to note is that [^(?:javascript)] and [^(javascript:)] in both situations (eregi and preg) only prevent the first character after the being j,a,v,a,s,c,r,i,p,t or : (depending on which one). While this does prevent the first word being javascript (as the first letter would have to be J), it also prevents things such as [ url=joako.net ]dfsf[ /url ] or [ url ]joako.net[ /url ] which based on the fact that your not forcing people to have http:// at the beginning seems to suggest SHOULD be valid (but arent). Just thought i'd mention it.

     

    Also, the first letter cant be 'j' but it can be a space followed by 'j' which will still work in allowing javascript into the url so you may want to consider revising the regex.

     

     

     $article_text = preg_replace("#\[url=(?!\s*javascript:)([^\[]+)\]([^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\2</a>", $article_text);
    $article_text = preg_replace("#\[url\](?!\s*javascript:)([^\[]+)\[/url\]#i","<a href=\"\\1\" target=\"_blank\">\\1</a>", $article_text);

     

    The code above SEEMS to work for what I'm assuming your trying to do.

  3. $a = preg_replace( '/<(?!\/{0,1}(?:table|tr|td)[a-zA-Z0-9\-\.,_\?\s\\\'\/\+&%$\#\=~;]*?>)/', '<', $a ); // Less thans

     

    for the less thans sorry (forgot to add the space to the character class in there).

     

    However doing the same with a Negative LookBehind for the greater thans is proving more of a problem as the LookBehind require the regex within to be a fixed length (ie same number of characters being matched) and so things such as the non-greedy character class repetition in the less than regex wont work. I'm trying to figure out a way to do it but i haven't got my hopes up.

     

    A simpler way as i said before with the ignoring, is simply to replace the tags you need with a special symbol or string and store them and then go back after the replacement of the <'s and >'s and replace the symbols with the correct replacements but you said you wanted a single regex for it so...

  4. $a = preg_replace( '/<(?!\/{0,1}(?:table|tr|td|th)[a-zA-Z0-9\-\.,_\?\\\'\/\+&%$\#\=~;]*?>)/', '<', $a ); // Less thans

     

    Seems to work for the less thans, the greater thans are a little bit more tricky (due to restrictions placed on the length variability of Negative LookBehinds). Bare in mind that theres probably a much simpler method than this (some of it is there to ensure stuff like it isnt just cheese<table etc which still needs to be matched) and Ive just got back from work and it's late. I'll take another crack at the greater than replacement in the morning (after i get back from work again around 2 oclock GMT) when ive had some sleep.

  5. To be honest, I'm not sure it's that simple. Adding additional things to match is fine but negating things and matching others at the same time becomes quite a bit more complicated. I tried doing what you said using Negative Lookbehind and LookAhead but it doesnt seem easy to get it to work properly in all situations.

     

    I just cant find anything to simply require that a string not be there for a match (as this is hard to do as if the string cant be there, it will just match everything after the string instead). There may be an easy but non-elegant way of doing it by negating specific characters and i'll try a few things out when i get home but I don't think it's as easy as it might seem.

  6. It's because in Fib2 you are doing far fewer calculations because when calculating the low number it has already been calculated when calculating the high number.

     

    Take for instance - Fib(5)

     

    It will do -

     

    Fib(4) + Fib(3)

    which in turn does

    (Fib(3)+Fib(2)) + (Fib(2)+Fib(1))

    which in turn does

    ((Fib(2)+Fib(1)) + (Fib(1) + Fib(0))) + ((Fib(1) + Fib(0)) + Fib(1))

    Which in turn does

    (((Fib(1) + Fib(0))+Fib(1)) + (Fib(1) + Fib(0))) + ((Fib(1) + Fib(0)) + Fib(1))

     

    Which is where it terminates giving an answer of 1+1+1+1+1 = 5 (this has been stated by Dave).

     

    Notice the amount of repetition of Fib() calls with the same value. What this second procedure is doing is storing previously called values from each recursive step in a static variable (a variable that has a defined memory for that function rather than for each function call meaning its value will be the same across function calls, meaning you can store something one function call and access it the next) and then when you make the next call if the value has already been calculated you have it there.

     

    For instance take Fib(4) -

     

    1st Level of Recursion -

    Fib(3) -> Second Level Of Recursion -> Value returned

    Fib(2) -> Answer is already in that static variable so it goes down a level and that wonderful if statement returns the value.

     

    Second Level of Recursion -

    Fib(2)-> Third Level

    At this point it then stores the answer to Fib(2) in the static variable (high).

     

    Third Level

    Fib(1) -> Return (ie goes back to Second then third)

     

    This happens on various levels and so it greatly reduces the order of complexity of the algorithm.

     

    The way ive explained it is rather strange but it seems a hard concept to grasp unless you're face to face and I find it hard to explain myself sometimes. Feel free to ask questions or challenge anything ive said, perhaps someone could explain it further.

  7. Just to detail what the original problem might have been, shouldnt the line -

     

    $article_text = substr($article_text, 0, $linkpos - 1) . substr($article_text, $linkpos - 1, ($linkendpos + 2) - ($linkpos - 1)) . substr($article_text, $linkendpos + 2, strlen($article_text) - ($linkendpos + 2));

     

    have been something along the lines of -

     

    $article_text = substr($article_text, 0, $linkpos - 1) . $newlink . substr($article_text, $linkendpos + 2, strlen($article_text) - ($linkendpos + 2));

     

    Thereby placing the new link in the place of the old [[Link]].

     

     

     

    Agreed with Dave, regexps are much nicer and make alot of sense once you get to know them (to be honest his regexp there is easier to read than the while code made to do the same thing (not saying your code is nasty, just that the regexp is short and sweet)).

  8. Icheb, he didnt say in that post that it did anything server side and he even agreed that XML didnt do anything server side (which obviously it couldn't as XML is just a markup language like HTML or similar which doesnt actually do any processing).

     

    All Pangloss said was that it was a way that could change the way web applications are handled and reduce the need for heavy server side applications which is perfectly true in that it means whole pages dont have to be returned (with the whole POST form, get returned a whole new page, POST something else get a completely different page etc) (saving bandwidth) and often as Pangloss mentioned in his previous posts, alot of content is static but just requires processing to be displayed correctly depending on the user's input which is fine for AJAX.

     

    While you may not agree that this is a radically new way of doing things (and i agree with you, as similar things have been done for a long time, as well as the fact that its simply an almalgamation of 2 existing technologies and not a technology in of itself, as well as the fact that effective caching technique and good design can offer similar benefits), Pangloss is entitled to his opinion there.

     

    I respect that you have experience and may know alot about the subject and I'm sure Pangloss does but I think sometimes it would be nice if you would at least admit that perhaps you are misunderstanding what someone means or says. You seem to be taking this a little bit personally. Sorry if i have caused any offense and obviously feel free to comment on what i have said.

  9. If this is true then it does still represent a major change in the way web applications can be developed (I disagree with Icheb on that, but I respect his opinion on it), and vastly reduces the need for "heavy" apps like PHP and ASP.NET delivering full-blown web pages to the end user. But you're right, it's still got to have some sort of piece at the back end doing the database work. PHP, ASP.NET, CGI, whatever. Maybe something else entirely ("legacy" apps, as indicated in the image). In fact it seems to kinda open a few doors there, doesn't it?

     

    Agreed :D Although techniques similar to AJAX (like using hidden Iframes and requesting script responses via that etc) have been around for a while, the fact that AJAX offers a clear and standardised way of doing it (Javascript's XMLHttpRequest() + XML feeds etc) and the fact that it is gaining so much popularity (due to its obvious advantages) recently make it an idea/technique to be counted :D

  10. I agree that AJAX would work fine accessing and displaying/processing static content, but i disagree with you on the direct accessing of the database and I don't think you could illicit requests to the database using XMLHttpRequest (rather than HTMLHttpRequest which as far as im aware is central to AJAX (never even seen it)).

     

    Not sure if you mean that there are some databases that are happy to serve up XML data and recieve queries (ie insert/update queries) via Http requests but then i would say that that database was the server side processing rather than simply AJAX.

     

    XMLHttpRequest is simply a function that sends a Http Request to the webserver for an XML file/ Something that requests the XML content and then the XML is processed by the function into a nice simple DOM object that can be used easily to parse the XML and use its contents, as far as i am aware there isnt anything magic about it that would allow it to manipulate databases or change anything server side. Therefore doing something dynamic that requires something to be stored server side (ie in a game, a messageboard (as you said), banking, almost any sort of portal etc) wouldnt work with a purely AJAX approach.

     

    Maybe I'm misunderstanding what your saying, maybe I'm misunderstanding the AJAX approach or something involved. These are just my 2 cents.

     

    XMLHttpRequest Info

     

    PS - Maybe we should move the AJAX specific conversation over to another thread or something ?

  11. Pangloss, I think the problem is that JavaScript is used in the context of AJAX as a client side scripting tool (ie browser etc) rather than server side and static XML pages server side really wouldnt do much, there would have to be something server side to generate these XML pages or to serve them up (ie PHP, Perl, or if that link i pasted is accurate, server side JavaScript) or otherwise the content wouldnt be dynamic (ie accessing database etc, a simple XML page won't access the database for you unless you set some other script up server side to do this).

     

    While JavaScript apparently can be used as a server side script (although i havent seen it and i dont think its used very often), that isnt the case with AJAX, AJAX simply refers to the client side javascript interacting with something serving up XML on the server side (whether that something be an XML document or cgi script serving up XML content), which is where saying AJAX could replace PHP or Perl as a solution doesnt seem to make sense as AJAX refers to the client side aspect and the method of communication (XML content) with the server side aspects.

     

    PS- I'm no expert and you may well find evidence to the contrary but this is what I have read, understand from what I've encountered.

  12. Icheb, i wasnt agreeing that AJAX could be used for Server Side scripting, I was simply agreeing in that Javascript is one tool used to do what AJAX does (which is what was stated in the following text). Sorry if this was ambiguous.

     

    Also i posted my response but didn't see that there was another page to the topic. I didn't mean to reiterate what was being said. tje problem is once I've made the post I can't delete it. These posts (my original post and the replies to it) should be deleted but I obviously can't do that myself.

     

    The only acronym i used was SSJS which i thought would have been simple enough considering i already mentioned Server Side JavaScript just before that point and it is also mentioned in the link i posted. It was not meant to try to show off in any way.

     

    And yes i agree i should have spaced it out more.

  13. CGI is a "protocol" of sorts; it's just a set of guidelines for things like webservers to pass data to programs and receive content from them.

     

    Say you send a request to the webserver for test.cgi. In a perl script' date=' the first line is usually something like #!/usr/bin/perl, which tells the webserver to execute: /usr/bin/perl test.cgi. Perl then parses the document, reads inputs from stdin from the webserver and outputs to stdout - the webserver then reads that output and serves it to the client.

     

    With an executable, it's exactly the same process. The first line might be something completely different, but apache "knows" to execute the program and pass in a load of data to the program to stdin, and expect a load of information from stdout.[/quote']

     

     

    albertlee, I think dave's explanation already explained this. CGI itself isnt a language it is just a standard/protocol/interface that the webserver is setup to use that lets it know when and how to interact with executable files and to pass data back and forth to them to be processed for output.

     

    Heres another link that might explain it some more - Wiki on CGI

     

     

    AJAX is no alternative to PHP! AJAX only supplies a method to access server-side scripts without having to reload the page. It's just a derivative of Javascript and has been around for a looong time now' date=' but it gained popularity after Google started to use it so extensively.

    [/quote']

     

    I beleive JavaScript is a form of AJAX and not the other way around. It has the ability to perform in any host environment so it could very well replace PHP.

     

    Agreed for the most part. The term AJAX refers to Javascript (ie Asynchronous Javascript and XML), however the way in which it works can easily be done with VBScript or any other client side browser scripting language. It simply involves using that client side browser scripting language to make requests to the server scripts (could well be PHP or Perl that simply serve up XML data rather than a static XML document (i would consider this much more likely otherwise it wouldnt make much sense)) (in the case of AJAX, the common request method being the use of the function XMLHttpRequest()) which in turn return only the data necessary (what was requested), which is then used by the client side browser script to alter the contents of the page to match the new data. This means that the whole page doesnt need to be refreshed, only a small amount of data needs to be transfered (ie the changes or additions), therefore saving bandwidth and offering a much more responsive and interactive site/application (ie doesnt require changing of pages as the browser script does it all behind the scenes).

     

    JavaScript, despite what I would have thought does have a Server Side equivalent but from what I know that is nothing to do with AJAX primarily (although SSJS could be used to serve up the XML from the server side i suppose). I havent heard of it being used much but i have found mention of it.

     

    SSJS

  14. I think its a simple case of setting up your webserver to recognise certain filetypes and extensions are cgi (ie to execute them correctly and use the output rather than using the files contents).

     

    For apache -

    http://steinsoft.net/index.php?site=Programming/Code%20Snippets/Cpp/apache-c-script

    A small tutorial on using C as a CGI language -

    http://www.cs.tut.fi/~jkorpela/forms/cgic.html

     

    Its all a case of handling http request info and sending back valid http responses (one of the reasons php is so easy, it does so much of this for you).

  15. I would say that the main reason is that PHP was designed specifically for the purpose of serving dynamic content via webservers. While perl, admittedly, is a great language, programming for it can be a real pain sometimes, especially since it has to be run under CGI (most of the time).

     

    Yeah, with things like $_POST/_GET/_SESSION etc having all the session handling and grabbing of post and get data done for you, PHP is alot easier to work with for web content than Perl (which as far as i have seen requires you to parse/regex out the POST vars from the various environment variables set from the http headers (although there are probably some modules etc available that make this much easier). With the ease with which one can setup simple sessions or cookies and the ease with which they can be maintained in php, it no-wonder it is often used for web development. Also, by default in php there are so many functions that will simple do alot of your work for you and the php.net documentation is very easy to handle and using that and a few tutorials, php can be picked up in no-time (although obviously as with anything, theres a difference between doing something and doing it well), where others such as Perl can be somewhat harder to pick up (Perls semantics can be rather difficult if you havent done any programming before and the code can be rather hard to work with if you dont actively try and keep it neat (although this can be said of any language, it is especially true in this case in my opinion).

     

    Links -

    Wiki on PHP

    More on PHP's Predefined Variables (_POST,_GET,_SESSION etc)

     

    PS- Not saying this to you Dave as you already know it :P, just mentioning it as an additional comment/aside :D

     

    PSS - Also I don't dislike Perl before anyone rants at me, I love it :D Just, right tool for the right job (sometimes that can be perl (it seems to have a much lower footprint than PHP (ie the memory usage because of the fact perl doesnt have nearly as much included by default (preferring modules) means it uses far less memory for the interpreter when running)) and has been perl in alot of high profile sites) :D

  16. Chr 7 is specified[/i'] as beep in the ASCII system. It belongs in a group of other characters like Chr 2 (enable printer) or Chr 13 (new line). These are not displayable characters but cause something to happen.

     

     

    Yep. Here's a look at the ASCII chart for anyone who is interested (this is the extended 8-bit ASCII set, whereas the default older one was only 7-bit (ie Just table I)).

     

    ASCII Table

     

    Wiki on ASCII

     

     

     

    Ended up playing alot with ordinal character/ASCII values for my Computing project when i wrote myself a nicer read/readln() procedure for my Turbo Pascal Project. Was fun :D

  17. Hehe, most major problem ive had with portage is when the new ATI drivers didn't want to play nice with the new XOrg release and so i had to put an entry in package.mask and just wait until the ATI or XOrg releases were fixed to compensate (although portage was decent about it, it would unmerge the newer ATI drivers and replace with the old every other update so it was a case of "emerge new drivers" "unmerge new drivers" "emerge new drivers" etc, was quite funny).

     

    Apart from portage itself though, you have to love the gentoo forums. Theres always a wealth of help available there (although i wish the search system was slightly better sometimes :P ).

  18. If your really looking for something suited to you and something that will help you learn new things about various operating systems and computing in general, why not try something like Linux From Scratch. It wont necessarily be easy to update or continue with but you could probably introduce a package management system at a later point from one of the other popular distros.

     

    http://www.linuxgazette.com/issue49/misc/beekmans/LFS-HOWTO.html

    http://www.linuxfromscratch.org/lfs/whatislfs.html

     

    I haven't actually done this myself but plan to give it a go at some point (probably on a VMWare partition until i find a new cheapy HD for it) as I feel it would be a good learning experience as you end up having to do pretty much everything yourself and you learn alot about the bits and bobs of a linux operating system and alot about how the linux and other operating systems work.

     

    Also as dave said, gentoo is good :D (LOVE portage :D)

  19. Pangloss the JVM (Java Virtual Machine) is what you are talking about and it takes the bytecode files (.class) and runs those rather than the actual source code file. The source code file is compiled by the java compiler into byte code when the software developer decides to do so using javac (java compiler).

     

    http://en.wikipedia.org/wiki/Java_platform <--- Note there it says bytecode (which if you click on the link will explain that this is not simply the source but a half-compiled, intermediate step)

     

    Not sure if you mean byte code or source code but I felt it needed clarification. Sorry if i misunderstood you.

     

     

    [EDIT]

    Looking in my java folder (on my gentoo desktop (couldnt find the source files on my laptop)), it seems that the .java files in the src.??? (zip in my case) are source files for various classes and packages that you can include when creating java programs. Looking inside alot of them (although i havent had a chance to check them all, nor can i account for anything others might find in different versions), it seems that the classes defined are simply wrapper classes for older versions or something (ie there isnt much code content other than instantiations of / extensions to default java classes (ill show an example of what i mean when im on my desktop for a bit)), which if true for all/most of them means that this might not be open source, but more extensions or compatibility allowances.

  20. You download the output from the php script having been parsed by the php interpreter.

     

    If the webserver isnt set up correctly (ie setting up .php extensioned files so that they are interpreted with the php interpreter (usually involves AddType etc in Apache)), then the php file (actual code contents) is sent when you request the file. But normally when you make a request for the file to the webserver, the webserver knows not to simply send the contents (as it has been configured with .php scripts in mind) and so the file is parsed through the php interpreter and the output of that send by the webserver to your PC. If the webserver is setup properly you cannot just 'download' the php file with its code contents, as the webserver will always allow it to be parsed/interpreted by the php interpreter first.

     

    Not sure if thats what you mean but..........

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.