Jump to content

Case-Sensitive

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Everything posted by Case-Sensitive

  1. My reason to use it is for visiting and discovering web pages within a website structure and the visitor pattern seems to be ideal for that (I think). 1. Ive implemented a crawler that searches a website and places the pages its found in a collection 2. I use the visitors(stored in an array) and pass them along to the collection and they perform their tasks as needed. Step 2 is my worry, Is there a better way to implement the pattern so i reduce the step of storing it in the collection and just perform the tasks when it finds a new page cheers for your help
  2. Hey guys Wondering if you could give me a little hand here. Im trying to get the attributes from a tag. e.g .... id="some-value" name="some-value" .... the regex im using with preg_match is: $pattern = '/(\w*=\".*\"\s*)/'; this matches all the attributes but does not split them, so what would i have to get each inidvidual attribute I tried using explode with " ". However if the attribute value has a space within the quotes, it doesn't work. Any help would be great Cheers
  3. Hey Yeah I want to implement it and learn about it as well. I have been doing some reading and I found a solution to iterating different visitors over one collection: foreach($allVisitors as $visitor) { $indexed->accept($visitor); } is that right, this then brings me to the question - if i have two visitors they both duplicate iteration (it may be an advantage because they can implement their own visit functions and do whatever they want. How would you make it so that the Visitable object can iterate its own collection and each Visitor performs it function per element. any help be great
  4. Hey guys I want to use the visitor design pattern. I kind of understand but thought you guys might help more Should each visitor perform its own actions on the collection it visits, if so is this concurrent in php? Are there locks in place to prevent access when another visitor is iterating through the same elements of the collection. any help on this would be great cheers
  5. I'm gonna use explode(), if im right this would result in a proper html page when you print each element out from the array. thanks
  6. Hey cheers I was thinking of that, but since ive been working with php's DOM functions to get the url and then apply a dom to it: $ch = curl_init(); //set options for the curl session curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); //fetch the url and store it as a string $site = curl_exec($ch); $connInfo = curl_getinfo($ch); //close the curl session curl_close($ch); $domObj = new DOMDocument(); $domObj -> loadHTML($siteString); I was thinking if there was a function that i didn't know about, that integrated with CURL/DOM cheers, I will try the suggestion!
  7. HI guys I was wondering if its possible to get the line number from the html page retrieved using CURL and parsed with the DOM. An example is bobby validator, which looks at your html page and then tells you if you got a problem, including the line it was found on. I was thinking of saving the parsed dom back to a tmp file and then reading it a line at a time, making note of the line. But this is not very efficient. does anyone have any ideas? any help would be great thanks
  8. Oh! Sooooooooooooooooo sorry, I just got what you meant! if Count() returns the number of total elements its there for returning the next position available $array[0] = "A" $array[1] = "B" $array[2] = "C" $array[3] = "D" $array[count($array)] = "E" would place it in the next position which is 4! Thanks fret, sorry for being a nooob!
  9. I just looked the function up and it seems to do the same job as sizeof(), which ive used already. $array[0] = "A" $array[1] = "B" $array[2] = "C" $array[3] = "D" The array above contains 4 elements, but because arrays start at 0 not 1 the position to place the next element needs to be -1 of the total elements. Any other ways that this could be done cheers for your thoughts.
  10. Hi Guys Ive got an array called $links inside a class and i want to be able to add things to the end of this array (store info in the object). So what I did was to have a function, like so: public function AddToLinks($ALinkObj) { $iter = (sizeof($this ->links)) -1; $this ->links[$iter] = $ALinkObj; //$iter++; } The problem is with this $iter = (sizeof($this ->links)) -1; , every time the array gets created (arrays start at 0) the function above will make the array position equal to -1. Is there a clever way to avoid the array beginning from -1 and taking into account that a value is already present in position 0. Any help would be great Thanks alot
  11. Im guessing no one replied because of the stupidness of this post. I just realised how Stupid it was (not me)! After thinking about it, it was a useless post, which created more server processing thus adding additional carbon emissions to the atmosphere (apologies to your children) If all sites start at root, all i had to do was prefix the url (that was given at the beginning) of the site to the href attribute: [code] $url_to_test="http://www.example.com/"; $href = "about.html"; [/code] then concatenate the strings, so it would give a well formed url: "http://www.example.com/about.html": [code]$url_to_test.$href;[/code] Sorry Guys
  12. Hi Im trying to turn a href attribute from a link <a> element into a url. The problem Im having is that the link <a href="index.html">home</a>, just stores the filename, so when I try and use curl to get the contents from the page it gives a "unresolved host error". Which is because of the value in  the fref is not a well formed url string. Is there a way of getting the servers path e.g http://localhost/site so i can prefix it onto the href attribute before passing it to the curl function. Ive tried the following, but it does not give a url, it does give working directories and stuff print("<pre>"); print_r($_SERVER); print("</pre>"); Any help or ideas would be great Cheers
×
×
  • 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.