Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. If the field is of type INT it doesn't require quotes.
  2. back ticks shouldn't even be used unless you're using reserved words.
  3. I still don't see any \n's.. Even if there were any my last post included something that would remove them all. Example: $text = file_get_contents('advertisements.txt'); preg_match_all('~"text"\s+"([^"]*)~', $text, $matches); $arr = array_map(create_function('$t', 'return str_replace("\n", " ", $t);'), $matches[1]); echo implode("<br />\n", $arr); Would output: Our PayPal email has changed to jamesross_134@hotmail.com\nSend donations or admin payments to this new address. For double points, type !donate and then use the link printed to your console to make the payment. To see what your Steam ID is, simply type !steamid in chat. To easily donate for double points, or to purchase admin, type !donate in chat. Type !motd in chat to find out how to purchase admin, donate, or to re-read the server rules. Don't use exploits or bugs.\nDon't use offensive sprays.\nDon't swear at anyone.\nDon't block.\nDon't spam. Don't point farm or support point farming.\nNo sexism, no racism, or any other form of baseless hate. Type motd in chat to find out how to purchase admin, donate, or to re-read the server rules. Current map is {CURRENTMAP}, next map will be {SM_NEXTMAP} Admins: When pmuting/gagging a player, always provide a reason\nFor example sm_pmute bob 'whining all the time' Admins: Do NOT overwrite other admins decisions by un-banning/muting players who've been permamuted or banned by higher admins. Admins: If unsure about unmuting/unbanning, contact either Cherry or Indigo. Say !maprate to rate the current map and view current ratings! Join Penis's awesome Ventrilo server: 208.100.9.200 : 9209 Donators / VIPs now can set a custom player model! Type !model in chat to open the menu. Visit http://sammyservers.com for info about our servers, how to donate, buy admin and view a list of all the admins. Admins: Before touching anyone, \nuse sm_report <'player name'> <'reason in quotes'> on them first. Before thinking about buying admin, carefully read the motd and the website, and do not send money until you are approved. In need of an awesome spray? Contact Taters by adding Willy on Steam!
  4. Aren't the line breaks (\n) already taken out when we parse the file with preg_match_all? I have a feeling you're misunderstanding the problem and this is what you want: <?php $text = file_get_contents('advertisements.txt'); preg_match_all('~"text"\s+"([^"]*)~', $text, $matches); echo implode(" ", $matches[1]); ?> If you wanted to go through all the elements and replace any line breaks with a space (even though I'm pretty sure there are none), you could use array_map <?php $text = file_get_contents('advertisements.txt'); preg_match_all('~"text"\s+"([^"]*)~', $text, $matches); $arr = array_map(create_function('$t', 'return str_replace("\n", " ", $t);'), $matches[1]); echo implode("<br />\n", $arr); ?>
  5. if(strtolower($name) == "ian") strtolower
  6. I'm not sure what you mean. There's no line breaks (\n) in there besides the ones I added on: echo implode("<br />\n", $matches[1]); If you want to move that just replace the \n with ' ': echo implode("<br /> ", $matches[1]); By the way, the reason what you tried wouldn't effect $matches[1] is because, well for 2 reasons mostly: 1. $matches[1] is an array, not a string 2. str_replace doesn't take the string by reference so you would need to do something like: $str = str_replace($search, $replace, $str);
  7. For debugging purposes it's usually a good idea to put error_reporting(E_ALL); at the top of your script. Just glancing at your code I think your error is probably here: if ($action == commentsend) { I think what you want is: if ($_GET['action'] == 'commentsend') {
  8. Looks like you were on the right track. Try this: <FORM ACTION=""> <select name="jumpto" onChange='window.location.href= this.form.jumpto.options[this.form.jumpto.selectedIndex].value'> <option selected># Per Page</option> <option value ="index.php?type=<?php echo $_GET['type']; ?>&size=ALL">All</option> <option value="index.php?type=<?php echo $_GET['type']; ?>&size=100">100</option> <option value="index.php?type=<?php echo $_GET['type']; ?>&size=50">50</option> <option value="index.phptype=<?php echo $_GET['type']; ?>&size=25">25</option> </select> </FORM>
  9. file will load the file as an array, which is not what you want, so you'd be better off with file_get_contents. You can display the information like: $text = file_get_contents('advertisements.txt'); preg_match_all('~"text"\s+"([^"]*)~', $text, $matches); echo implode("<br />\n", $matches[1]);
  10. sort doesn't return the sorted array, it returns a boolean indicating if it was successful or not. It takes the array by reference, so this how you would use it: $arr = explode(',',$_POST['nums']); sort($arr, SORT_NUMERIC); print_r($arr);
  11. $text = <<<TEXT "Advertisements" { "1" { "type" "S" "text" "Ad1" } "2" { "type" "S" "text" "Ad2" } "3" { "type" "S" "text" "Ad3" } } TEXT; preg_match_all('~"text"\s+"([^"]*)~', $text, $matches); print_r($matches[1]); Output: Array ( [0] => Ad1 [1] => Ad2 [2] => Ad3 )
  12. You didn't say you were trying to find sample standard deviation.
  13. Figured it out, this is what I was trying to post originally.. [tex]\sigma = \sqrt{\frac{\sum_{n = 1}^n (x - \overline{x})^2}{n}}[/tex]
  14. Well after 10 minutes of trying to figure out how to use 'bar x' in the [tex] tag.. You can install the math extension, or just create your own standard_deviation function, it's not that hard.. Ex: <?php function standard_deviation($arr) { $bar_x = array_sum($arr) / count($arr); foreach($arr as $x) $dev[] = pow($x - $bar_x, 2); return sqrt(array_sum($dev) / count($arr)); } echo standard_deviation(Array(78, 84, 86, 92, 95)); // 6
  15. You're missing a ; at the end of this line: error_reporting(E_ALL)
  16. You didn't fix one of the indexes, or take off the error suppression from copy. Is that your whole code? If so you're never closing your if statement, which is why you're getting that error. if ($_FILES['img1'] != "") { copy($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name1']) or die("Couldn't copy the file."); }
  17. Basically, here is some good reading on word boundaries in regex.
  18. Whoops, I made and tested a solution to this problem but forgot to post it $str = '<span id="1">test string</span><span id="2">test string2</span>'; $input = '1'; $str = preg_replace("~<span id=\"$input\">(.+?)<\/span>~", "$1", $str); echo $str; // test string<span id="2">test string2</span>
  19. You should take off the error suppressing from copy (@) so you can actually see what's going wrong, another good idea would be to put error_reporting(E_ALL); at the top of the file. Once you do that you'll get a bunch of undefined constant errors, you should surround indexes with quotes if they're strings. Ex: $_FILES[img1] should be $_FILES['img1']. Once you do that post back the error that copy is throwing.
  20. The word boundary, \b, just matches anything that might border a word. Ex: space, comma, period, etc..
  21. You can use preg_replace to do this. Example: $old="apple"; $new="lemon"; $str="I have got one green apple, two yellow apples, oranges and grapes."; echo preg_replace("~\b$old\b~", $new, $str); Edit: Angy-H's solution will only work if the occurrence of the string that you want to replace is the first one in the string.
  22. There's no reason why it shouldn't work with 5 parameters.
×
×
  • 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.