Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. yes, with lookaround
  2. name and id are two different things. if each div has its own id (and it should), you can use getElementById
  3. put quotes around your variable in your query
  4. That regex isn't right. You can't put blocks of text inside character classes like that. Character classes only match single characters, so that http:// is going to not match on any one of those characters, not the whole thing. That's what lookbehinds and lookaheads are for. ~<img.*?src\s?=\s?"(?!http:)[^"]*"[^>]*>~is
  5. You can't stop the user from refreshing the page with php. It has to be done with javascript. What you can do is start a session and use a session var to track whether the user has gone to the page or not. User goes to page, session starts, var is set to 1 or true or whatever. User refreshes, new request sent to server, server checks for var. var exists, so display something different.
  6. If your other vars being passed via GET are working fine, chances are, you mispelled 'Pressure' in your form or link, wherever the vars are being passed from.
  7. There's nothing wrong with the code you provided. that code removes all commas from whatever is in element $i of $line_info and assigns the result to $val. Now if you want to know why it's not working within the context of your code, perhaps you should post the code it's being used in.
  8. just read the notes in the manual for highlight_string() there's a ton of entries doing exactly what you want.
  9. $img_array = glob("/path/to/images/*.{gif,jpg}", GLOB_BRACE);
  10. order by column1, column2 default is ascending for both. You can specify the ascending or descending by adding on asc or desc like so: order by column1 asc, column2 asc order by column1 desc, column2 asc order by column1 desc, column2 desc order by column1 asc, column2 desc Note that it will first ordery by column1, then within that order, it orders by column2.
  11. thread closed. Read stickies.
  12. look at the basic database interaction tutorial on this site. The tutorial walks you through a form that lists stuff and lets you add/edit/delete stuff from the list. You can tweak it from there.
  13. dude...it's an array. the print_r was to just dump it so you can see how its structured. Use a foreach loop to loop through each element and display it how you want it.
  14. That's terribly inefficient and downright impossible. www.google.com/ANYFILENAME?ANYVARNAME=ANYVALUE[&ANYVARNAME=ANYVALUE[...]] makes the number of valid google urls infinite. Better to just search for 'google' in the link somewhere or restrict where to look with regex.
  15. Quick and simple: $array = array('www.google.com','www.yahoo.com','www.somesite.com','http://www.google.com','site2.com'); foreach ($array as $link) { if (!stristr($link,'google')) { $newArray[] = $link; } } The limitation to this is that it will match links that contain 'google' regardless of where in the link it is. So if you have a link like www.mysite.com/google/somepage.php or www.mysite.com/somepage.php?site=google or some other link that would have 'google' in it but not actually be a google page, those won't make it to $newArray. If you are worried about something like that happening, you're going to have to use preg_match instead. There are a ton of examples in that link and on the net for checking for a valid url. All you need to do is swap out the wildcard used for the domain name to specifically check for google. Alternatively, you can do $key => $link in the foreach loop and unset($array[$key]) on match, to work with the original array. Same stristr limitations would apply.
  16. right, but I thought you could only define simple, scalar values, not arrays or use other things like operators? Like, you can define it as an array declaration like so: var $blah = array(); but you can't assign any values to it.
  17. not that great at OOP but I don't think you can assign values to properties. Have to do it in the constructor or a regular method that's called from the constructor or calling it manually after instantiation.
  18. $string = "cats"; $array = array('cats','dogs','mice'); if (in_array($string, $array)) { // true, do something } else { // false, do something }
  19. Nah...not that hard to understand, but it's a little more complicated than that...this tutorial explains basic database interaction. The concept, how to do it, etc...
  20. http://us2.php.net/manual/en/features.file-upload.post-method.php
  21. haha sorry, what I probably should have said was "php is looking at the quotes in your image you put in there and it thinks that's the end of the string to print. To tell it that that's not the end of the string, you have to put a \ in front of it, or 'escape' it, so that php knows that's not really the ending " to look for."
  22. Main thing to remember is that php doesn't have the OOP syntax for things like var.length etc... instead it has predefined functions that you pass arguments to (the variable/array name, etc...). That's why despite the fact that you can make custom objects/classes/interfaces/properties/methods etc.. a lot of people don't feel php is truly an OOP language.
  23. Example: // grabs every line in the file and puts it into an array $lines = file('somefile.txt'); // starting line $start = 4; // array keys start at 0 not 1, so fifth element is 4 // ending line $end = 9; // 10th element is 9 // loop through and echo each line in the range for ($key = $start; $key <= $end; $key++) { echo $lines[$key] . "<br/>"; } This obviously isn't very efficient. If you have thousands of lines in your text file, every single one of them is going to be loaded up into memory. Unless you know exactly how long every line of the file is, you cannot specifically pull out a certain range of lines from a file. You could alternatively use fopen to open the file, and use fread in a while loop to go through each line, incrementing a var until you reach $start, and then doing something like printing or saving to an array each line of the fread, until it reaches $end. This also isn't that efficient. Even though you aren't putting the whole file into memory, you're still having to loop through each line until you get to your range. That's fine on "page 1" but when you're on page 100.... Alternatively, you could split your file into smaller files x lines long, representative of individual pages. file1.txt would have lines 0-9, file2.txt would have lines 10-19, etc.. and when the user clicks the next page link or whatever, it loads the next file using file. Since each file is only 10 lines long, you are only holding 10 lines worth of stuff in memory at a time, and you're not having to loop through all the previous "pages" to get to it. Simple foreach loop on the file array and you're set. Main downside to this is that you can't just change some variable to change how many lines per page to display. Alternatively, you could, you know, use a database, since that's what they are meant for.... As far as how to go from page to page, which I know you will eventually ask...the search term you are looking for is "pagination" so google that term for tutorials to understand the concept (btw there is a pagination tutorial on phpfreaks; you can read it to learn the concept, but it's based on database not flatfile). Go to the tutorial section on the main site).
  24. You need to escape the double quotes ( \" ) in your image link, just like those other escaped ones in that line, so that php knows that those quotes are not the end of the string to print.
  25. close...looks like you're mixing up some JS style coding in there. $data = mysql_query("SELECT worth FROM onlinegm"); $info = mysql_fetch_row($data); $dataArray = array (); for ($var =0; $var< count($info)-1; $var++){ $dataArray[]=$info[$var]; }
×
×
  • 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.