-
Posts
60 -
Joined
-
Last visited
Never
About Rithiur
- Birthday 03/06/1987
Contact Methods
-
AIM
Rithiur
-
MSN
rithiur@gmail.com
-
Website URL
http://rithiur.com
-
ICQ
58095275
Profile Information
-
Gender
Not Telling
-
Location
Finland
Rithiur's Achievements
Newbie (1/5)
0
Reputation
-
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
-
You are most likely missing a semicolon from the previous line that has code in it
-
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
-
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
-
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"; }
-
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)
-
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)
-
<?xml version="1.0" encoding="utf-8"?> in a php doc?
Rithiur replied to Guardian-Mage's topic in PHP Coding Help
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 -
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.
-
how to prevent data insertion when the page is post back
Rithiur replied to seco's topic in PHP Coding Help
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. -
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>"; ?>
-
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
-
[SOLVED] why the color not changing alternately??
Rithiur replied to angelsRock's topic in PHP Coding Help
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. -
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'. ?>
-
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 "£".