Jump to content

Drongo_III

Members
  • Posts

    579
  • Joined

  • Last visited

Everything posted by Drongo_III

  1. I changed what you used slightly but this will match both your class and the content of the div preg_match_all("|<div class='(.*?)'>(.*?)</div>|", "<div class='mainful'>this is testing of the string n thats it </div>", $out, PREG_PATTERN_ORDER); echo "<pre>"; print_r($out);
  2. Hi shadow This is quite hard to wrap your head around. The reason the order works like that can be shown with a normal variable. For instance: var1 = "TIM"; var1 = "My name is $var1"; echo var1; // Will echo "My name is TIM" I believe the reason this happens is because before the system assigns the new variable name to the second $var1 it's saying - "right, what does the value of the second var1 need to be?" And in this case its seeing a string "MY name is" followed by a variable (the first instance of $var1). So it evaluates that part of the statement - i.e. The new value for $var1 should be "My name is Tim" and then it overwrites the value held for $var1. At least that's my understanding of it...
  3. Hi mate Try this as the pattern: $patterns[0] = '/[^\w@.]/'; essentially that pattern means replace everything except what is inside the square brackets. The \w applies too all letters, numbers and the underscore. If you also want to add in a hyphen as an allowed character then use: $patterns[0] = '/[^\w@.\-]/'; Hope that helps matie I have had a good refresher in simple regex today hehe
  4. Better version $string = 'John_Smith 533r3r3 >>>'; $patterns = array(); $patterns[0] = '/[^\w]/'; $replacements = array(); $replacements[0] = ''; echo preg_replace($patterns, $replacements, $string); This replaces everything except letters, numbers or underscores.
  5. Hmm I would try something like $string = 'John_Smith fee334343'; // This is the pattern the pre_replace will use looking for matches $patterns = array(); $patterns[0] = '/[ \-_]/'; // The array value here that corresponds to the above pattern will replace matches //with the contents of the array value. So in this case it replaces anything found //in the pattern with '' - i.e. removes spaces, hyphens etc. $replacements = array(); $replacements[0] = ''; echo preg_replace($patterns, $replacements, $string);
  6. Hi mate Err I was having a fiddle with this and a much more simpler version would be: <?php $pattern5 = '/[\w]?[\d]+/'; $email = '111eeee'; if (preg_match($pattern5, $email)) { echo "your pattern matched"; } else { echo "Your patten didn't match"; } ?> That is a much simpler way of matching alphanumeric characters or just numeric. It won't match just letters though. Sorry looked at regex sooo long ago that i thought it needed to be a lot more complicated than it did!
  7. Hi mate Ok this is testing my limited regex knowledge to the limits here but i think this works: <?php $pattern2 = '/^(?=.*\d)|(?=.*\d)(?=.*[a-zA-Z]).{1,}$/'; $email = 'uhuuyyv576576576'; if (preg_match($pattern2, $email)) { echo "your pattern matched"; } else { echo "Your patten didn;t match"; } ?> It should match any pattern of letters and number, or just number but it won't match just letters...hehe confusing myself now...
  8. I think if you just want to match a single charcter you're over complicating it using regex. Try this: <?php $email = 'name@example.com'; if (strstr($email, '@')) { echo "your pattern matched"; } else { echo "Your patten didn't match"; } ?>
  9. Yeah it's really hard one mate. I would just try simplifying the query in your function to try and get it working so you can identify the problem. That's about all i can suggest at the mo :/ There are greater php minds here than mine tho so sure someone can help ya
  10. Oh sorry didn't see that bit. Mmm then i am a bit stuck on this one too :/
  11. Ok. Well first thing is to fix that error. Have you tried removing the mysql_real_escape_string($question)); // THIS IS LINE 177 from that line of code and seeing if it works then? That line is looking for a variable $question that hasn't been assigned yet (at least that's how the logic goes in my head). I would start by removing that and seeing what you get.
  12. Well I think when its parsed the system essentially looks for an opening { and if no other { is found then the next } is considered the closing one. Whereas is two { { are found then it will look for the next }} to close. That make more sense hehe?
  13. Bit hard to say without seeing the code in it's entirety i'd say. But yeah if you have session start at the top and it's the first thing then that should be ok. First off i would ensure you're getting data from your query. So comment out your session bit and just try echoing your $row[0] to make sure that bit is ok. Can you post more of the code and the function you start your session in?
  14. Couple of things: 1) did you start the session? Can;t see that in your code. 2)Before you set the session variable have you tried just echoing the query results to make sure you're getting data? Sorry if i'm stating the obvious.
  15. Try fetch row. All explained here - http://uk3.php.net/mysql_fetch_row
  16. Ahh sry wasn't trying to be pedantic i was just wondering if i was doing something wrong...as seems to happen every ten lines of code i write haha
  17. Sorry the reason i asked my question is because I thought you had to say something like if ($count % 4 == 0) { // Do the new line } When I tried using just [code] if($count % 4){ // Do the new line } It didn't work for me and just echoes the new line constantly :/ So trying to figure out if I'm doing something wrong or misundestanding the way it works. Or whether the code should have ==0 for this sort of function.
  18. Sorry to jump in on this one. What does the modulus evaluate to in your if statement? Is it looking for a division by four that has no remainder and if it finds it the statement is true?
  19. Does this line in your code work? $degree_id_query = "SELECT degree_id FROM degree WHERE degree_type ='".$degree_Array[$i]."'"; Surely if you wrap a double quoted variable in single quotes it will be taken as a literal and not the value it represents?
  20. The ^ character defines the start of the pattern and $ defines the end. preg_match("/^[a-zA-Z0-9]+$/") Not sure if it makes a difference but i would always put the ^ outside of the square brackets. For your logic don't you want: If (pregmatch(blah blah)) //i.e. if the prematch satisfies what you want from the username grab query { grab database stuff } else { invalid user }
  21. So besides my dubious logic inside the trim function (thanks for explaining that bit) it's ok to call a function from a while loop like this?
  22. I could be off the mark. But this sounds more like a .htaccess thing. Can't you just setup your .htaccess/mod rewrite to rewrite the url ? ok, thanks Is posible to convert all or one by one? and how ?
  23. Thank Btellez Explored a bit more into headers after your suggestion and got it working along what you said header("Content-type: text/csv"); header("Content-Disposition: attachment; filename=file.csv"); header("Pragma: no-cache"); header("Expires: 0"); echo $header . "\n" . $mydata; One thing I wanted to clarify. Is it ok to called functions from within while loops. For instance in my script I call a function from the while loop to trim the data - is that ok or do you think it's bad practice as it'll consume resources? Drongo
×
×
  • 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.