Jump to content

Rithiur

Members
  • Posts

    60
  • Joined

  • Last visited

    Never

Everything posted by Rithiur

  1. I'm not sure what exactly you're after, but you if you need the path to the currently executing file in php, you can use the __FILE__ magic constant. You can read more about it here: http://www.php.net/manual/en/language.constants.predefined.php
  2. You are most likely missing a semicolon from the previous line that has code in it
  3. If the .htaccess files are enabled on the host, you can disable the magic quotes using the .htaccess file by inserting the following line into the file php_value magic_quotes_gpc 0 If you're interested, I've written somewhat comprehensive article about the escaping issue at my blog: http://serversided.blogspot.com/2009/04/user-input-and-mysql-queries.html
  4. You have a bit of misunderstanding with the regular expression there. The contents inside the [ ] are the things that the character class matches (or since you have ^ at the beginning, what it doesn't match). Since you have [^*] in the first regexp, the character class matches anything but * character. If you use [^*?], it matches anything except * or ? characters. If you want to make a quantifier ungreedy, you need to insert the ? after the quantifier. In you case, your regexp should probably have something like ([^*]+?) (and remove the + outside the parenthesis, assuming you want the entire match into that subpattern). Also, the if you're using the ereg() functions, they do not support ungreedy modifiers. You should be using preg_ functions instead. Also, if you meant the [^*] character class to mean any character, you should probably be using dot (which matches any character, except newline unless dotall modifier is used) with dotall modifier 's' like: preg_match('#<div class="postbody_div">(.+?)<span class="name"></span></td>#s', $string, $matches); Oh, and if you meant to match any character with the [^*] character class, you might want to use dot instead like (.+?) since dot matches any character (except newlines, so you need to use the dotall modifier like 's' like /.+/s
  5. A simple for loop would do it for you. For example: $size = count($matches1[0]); for ($i = 0; $i < $size; $i++) { echo $matches1[0][$i] . "<br />\n"; echo $matches2[0][$i] . "<br />\n"; echo "<br />\n"; }
  6. You could be using eval to evaluate the expression, using something like $a= eval("return $y * {$quotes[$randomquotes]}$x;"); Personally I feel that is not very good practice, since using eval tends to lead into bad programming practices and often even into security holes in PHP code (when, for example, evaluating input that comes from the user). A better way, in my opinion, to solve your problem would be to use something like a simple if clause, like if ($quotes[$randomquotes] == '-') { $a = $y * -$x; } else { $a = $y * $x; } Much easier to understand in code and doesn't make the simple issue overly complicated. If you want to write it in a bit shorter form, you can use the ternary operator like: $a = $y * ($quotes[$randomquotes] == '-' ? -$x : $x); (it checks whether the expression left of '?' is true, and if so, it evaluates and returns the value before the ':' character, and otherwise it evaluates and returns the value right from the ':' character)
  7. Well, since you know the word you used to split the string, you could just manually add it to the array after splitting it. Of course, you can also use preg_split with couple flags like: preg_split('/(Ipkt)/', 'eri0Ipkt', -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY)
  8. You can also disable the short tags by adding the following line to your .htaccess file in the directory php_value short_open_tag 0
  9. Are you sure that the checkboxes have any value in the form? It also appreas that in your form there you have delete[] as the value, while you are referring to delete2 in your code. Also, It's better if you post the actual code and not pseudocode. The error may where you don't expect it to be, but it's hard to point it out, if you only post what you think is significant.
  10. A better idea would be store a session variable in the form page and also insert that same variable into the form. When the form is submitted, you check if the submitted variable in the form is the same as the one stored in the session. If it matches, you insert the new data, and if it doesn't, you give out some sort of error. Once the data has been inserted into the database, simply remove the session variable or save a new value into it, so that attempting to resubmit the same form will not be accepted.
  11. Arrays have internal pointers, which the function each() uses. Once the first loop has run through, the internal pointer will be at the end of the array, Thus, the second loop wont print anything because the pointer is already at the end and each() can't advance it. To reset the pointer to the beginning, you can use reset() function, like reset($data); before the next each() loop. You could also use the foreach loop like "foreach ($data as $k => $v)", because foreach operates on a copy of the array so it doesn't advance the arrays internal pointer. So, you could for example use this: <?php $data = array(); $data['one'] = 1; $data['two'] = 2; $data['three'] = 3; foreach ($data as $k => $v) { echo "".$k.": ".$v."<br>"; } echo "<br><br><br>"; foreach ($data as $k => $v) { echo "".$k.": ".$v."<br>"; } echo "<br><br><br>"; echo "one: ".$data['one']."<br>"; ?>
  12. A bit of a shameless plug, but I've written a PHP script for testing regular expressions, which at least personally I've found quite handy. The tool can be found online at: http://rithiur.anthd.com/regex/ In addition, if you'd prefer to run it on your local host (which can provide considerable speed increase), there is also download available at: http://rithiur.anthd.com/regex.php
  13. Replace: If ($color = "#FFFFDF") with: if ($color == "#FFFFDF") '=' is assigment operator, so currently your code simply always assigns the value "#FFFFDF" to $color, which then evaluates true (because the return value of assigment operator is the value assigned) and then the color is always assigned to "#DBFCFC". In other words, you should have been using == instead, because that's the actual comparison operator.
  14. Here's a better example of references. In the previous one, it doesn't really matter whether it's passed by reference or not. <?php $b = 'foo'; function makebar(&$arg) { $arg = 'bar'; } makebar($b); echo $b; // will output 'bar'. ?>
  15. This sounds like it could be because of some encoding problems. Is both the form page in UTF-8 and is the mail client reading the email as UTF-8? Also, make sure that the browser and mail client IS really using the character encoding. (because sometimes the clients may ignore character encoding) The reason it's displayed like that, is because the UTF-8 code in hex for pound sign is 0xC2 0xA3, which in Latin-1 charset translates into "£".
  16. spookztar: It would probably be better idea to post a new topic than reply in one marked as "solved". [quote author=spookztar link=topic=119794.msg715989#msg715989 date=1192289869] "1-80 of any type of character on the left side of the dot, and 1-5 alpha characters on the right side of the dot" [/quote] Here's a regex according to your spesification: [code]preg_match('/^.{1,80}(\.[a-z]{1,5})$/', $filename)[/code] As for security measures, if you have some sort of file upload system, then personally I would only allow spesific file types that are needed for the particular purpose. Other than that, it's kinda  hard to say anything spesific, since it depends a lot on what you do with them.
  17. No, it doesn't. Language construct "echo" takes any number of arguments, separated by comma. Thus using something like "echo 'foo', 'bar';" will output "foobar". This is in fact better than using the concatenation operator (dot), because the PHP does not have to first combine the string before outputting them. In addition, your code wont work as intended, because you put the variable inside single quotes, and variables are not parsed inside single quotes.
  18. There are three parse errors in that code. 1. In the code you posted, in line 13 you have $_POST['email'] inside string. This should be $_POST because you are not using curly syntax. 2. Line 13 has extra ; in the end, which should not be there because of the OR in the next line 3. There is extra } at the end in line 20 In addition, there is problem in your SQL syntax. You don't have quotes around the email, so MySQL doesn't understand it as string. Also, user input values should always be escaped, when entered into query in order to avoid SQL injections. Here is code that might actually work (plus, I added the mysql_real_escape_string there for escaping user input data) <?php include ("config.php"); // connect to the mysql server $link = mysql_connect($server, $db_user, $db_pass) or die ("Could not connect to mysql because ".mysql_error()); // select the database mysql_select_db($database) or die ("Could not select database because ".mysql_error()); // insert the data $insert = mysql_query("insert into $table values ('" . mysql_real_escape_string($_POST["email"]) . "')") or die("Could not insert data because ".mysql_error()); // print a success message echo "E-Mail Added To Database, starting to e-mail."; echo "<meta http-equiv=Refresh content=2; URL=mailing.php>"; ?>
  19. Function are not parsed inside strings, of course. You should be using something like this instead: while($row2=mysql_fetch_array($exec2,MYSQL_BOTH)) { echo '<tr>'; echo "<td width=100 align=center>", substr($row2['datePosted'],0,10), " </td>"; }
  20. You can either change the line: echo " <a href='?action=detail&category=$category&id=$p[5]'><img src='$p[1]' alt='$val'></a> "; To echo " <a href='?action=detail&category=$category&id=$p[5]'><img src='$p[1]' alt='$val' border='0'></a> "; Or, you could simply add the following definition in the CSS part: a img { border: 0px; }
  21. Perhaps you should join on where the customer_id = from_customer_id. I'm guessing you are currently joining all the rows to the owner's ID (since that's what customer_id is according to you), rather than the commentor's ID. In other words, you should rather be using: $bsql = "SELECT * FROM ".$glob['dbprefix']."StreamRush_profileComments LEFT JOIN ".$glob['dbprefix']."StreamRush_customer on ".$glob['dbprefix']."StreamRush_customer.customer_id=".$glob['dbprefix']."StreamRush_profileComments.from_customer_id WHERE deleted = 0 AND ".$glob['dbprefix']."StreamRush_profileComments.from_customer_id =".$ccUserData[0]['customer_id']." AND ".$glob['dbprefix']."StreamRush_profileComments.customer_id = ".$_GET['customer_id']." ORDER BY time DESC"; ps. Your code is not exactly what I'd call "readable".
  22. I actually had it that way initially, but decided to put the last portion outside for the simple reason, that when you use my regexp, the subpattern 2 will always contain the url. If you move the \1 inside, then it will contain url + the ending delimiter for attribute. Of course, you could then just use new subpatterns inside the conditional branches, but then you wouldn't have the url always in the same subpattern, so you'd have to add extra code to check which subpattern contains the url.
  23. Well.. to do exactly what you want, you can do something like this: $string = preg_replace('/\G(([^\'"]*|([\'"]).*\3)*)foo/Us', '$1bar', $string); That will replace all 'foo's that are not inside single or double quotes with 'bar's. Of course, do remeber, that if you are trying to match strings that contain text, the quotes used in words like "don't" also count.
  24. Well, hackish solution is to use output buffering, and if you later in the page needs to insert something into the page, just modify what's in the buffer. However, the good solution is to structure your web pages in such manner, that all the output comes after the code logic, so that when you start outputting, you already know everything there is to output.
×
×
  • 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.