Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by newbtophp

  1. I followed your example and some of the scores produce wild numbers such as: 4.8888888888889/5 Which makes it destroy my layout structure. :-\
  2. OK, bare with me - i've added a rating system (i've defined the mysql row etc., just havent added any way to calculate) to user uploads at my site, so users can vote: 0-5 and its out of 5, but the problem is, im not sure how to calculate the score (how many votes until it gets to 5/5?) , what are you suggestions - thanks
  3. I've got a problem, i want to echo some images depending on the $id, however for me to get that id i have to extract it from a query. So i've done that, but i want to extract all id's (not just 1), so i can echo images for all them ids (not just echo the images based on 1 id), so I did a while() loop, however doesnt seem to work :-\ My code: <?php include "connect.php"; $user = "Peter"; $sql = mysql_query("select * from game_main where user = '$user'"); while($row = mysql_fetch_array($sql)){ $id = $row['id']; } //do i have to do foreach $id as something?? $views = mysql_num_rows(mysql_query("SELECT userip FROM game_views WHERE sub_id = '$id'")); $sql3 = mysql_query("select monthstamp from game_monthlyfeatured where first = '$id'"); $num3 = mysql_num_rows($sql3); $sql4 = mysql_query("select weekstamp from game_weeklyfeatured where first = '$id'"); $num4 = mysql_num_rows($sql4); $sql5 = mysql_query("select daystamp from game_dailyfeatured where first = '$id'"); $num5 = mysql_num_rows($sql5); $sql6 = mysql_query("select date from site_featured where id = '$id'"); $num6 = mysql_num_rows($sql6); if($num3 == 1) { ?> <img src="../images2/game/game_awards_1monthly.gif" width="20" height="20" /> <?php } if($num4 == 1) { ?> <img src="../images2/game/game_awards_topweekly.gif" width="20" height="20" /> <?php } if($num5 == 1) { ?> <img src="../images2/game/game_awards_topdaily.gif" width="20" height="20" /> <?php } if ($views > 1000) { ?> <img src="../images2/game/game_awards_1000views.gif" width="20" height="20" /> <?php } if ($views > 25000) { ?> <img src="../images2/game/game_awards_25000views.gif" width="20" height="20" /> <?php } if ($num6 > 0) { ?> <img src="../images2/game/game_awards_modpick.png" width="16" height="16" /> <?php } ?> Hope someone can help, thanks.
  4. Im using getimagesize to detect the size of an avatar which is stored in a db. However getimagesize doesn't always seem to work (for e.g. if the image url's location is down) - it displays the following error, instead of the avator: Warning: getimagesize(http://imageurl.com/img.png) [function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in Heres my code: <?php if(!empty($cmnt['user_avatar'])) { list($avx, $avy) = getimagesize($cmnt['user_avatar']); if(($avx + $avy) > 200) { $avx = 80; $avy = 80; } } else { echo '<img src="../images/noavatar.gif" width="80" height="80" alt="No Avatar" />'; ?> Is their a way to resolve this issue, or perhaps echo a message instead of the warning displaying :/
  5. Any decent php formatter/beautifier/pretty printer class/function? I found the following whilst searching: http://www.codeassembly.com/A-php-code-beautifier-that-works/ http://www.phpclasses.org/browse/package/1783.html But both are not any good - they sometimes strip html tags and can cause syntax errors, any suggestions to alternativeS? :-\ Appreciate, all replies.
  6. Im having alittle trouble: [A-Za-z] I have the above regex to match letters, however they dont match special character letters like: ΓΏ
  7. You may also find this useful: http://www.phpguru.org/downloads/PCRE%20Cheat%20Sheet/PHP%20PCRE%20Cheat%20Sheet.pdf
  8. Thanks mate!! works perfect.!
  9. My try - altough no luck: $variable = preg_replace("#;echo '[\s]';#", "?>\r\n<?php", $variable);
  10. Hmm im having abit of trouble, how would i replace: ;echo ' '; (contains a new line after opening quote). with: ?> <?php Example: <?php include("../config.php"); ;echo ' '; $variable = "test"; echo $variable; ?> Would turn into: <?php include("../config.php"); ?> <?php $variable = "test"; echo $variable; ?> :-\
  11. Both would work - equally fine in this case. Thanks for that, strstr() is pretty nifty
  12. How would i remove everything before the first error_reporting(E_ALL ^ E_NOTICE); ? <?php if ($variable==false){print <<<EOF Error EOF; die(); } ?> <?php error_reporting(E_ALL ^ E_NOTICE); define('NAME', 'Email'); define('DIR', 'includes/cl_plugins/'); ?> Would turn into: error_reporting(E_ALL ^ E_NOTICE); define('NAME', 'Email'); define('DIR', 'includes/cl_plugins/'); ?> My attempt: preg_replace('~.+?error_reporting\(E_ALL ^ E_NOTICE\);~s', ''); :/
  13. Thanks Alex and Salathe! Salathe, the info was very useful, really appreciate it !
  14. I tried simply doing the following: <?php $file = file_get_contents('test.php'); $file = preg_replace("~base64_decode\('([^']+)'\)~s", base64_decode($1), $file); highlight_string($file); ?> but that returns me with an error: Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' in /home/user/public_html/file.php on line 6
  15. Neil's offline, i dont want to sound rude, but can possibly someone else take alook at this in the mean time?
  16. if ($file != "") { $filename = $_FILES['file']['name']; $goodfiles = array("jpg","pdf","doc","zip","xls","txt"); $ext = strtolower(end(explode('.',$filename))); if(in_array($ext,$goodfiles)) { // copy the pic to the current directory and delete the temporary file if (!copy($_FILES['file']['tmp_name'], $filepath . $filename)){ $msg = "There was an error uploading your file.<br>"; } unlink($_FILES['file']['tmp_name']); // update file in db $qry = "UPDATE table SET title='$file_title',url='$file_url' WHERE event_id = $event_id"; mysql_query($qry) or die ("Error during query!"); } else { $msg = "This file type is not allowed."; } }
  17. Heres my attempt: <?php //Don't work - just used my attempt as example $input = file_get_contents('test.php'); function recursive64($input) { $regex = "/base64_decode\('([^']+)'\)/Umis"; preg_match("/base64_decode\('([^']+)'\)/Umis", $input, $var); $input = base64_decode($var[1]); return preg_replace_callback($regex, 'recursive64', $input); } $output = recursive64($input); echo($output); ?> Lets say I have this code (within file.php): <?php $var = "test file"; $var2 = base64_decode('ZXhhbXBsZQ=='); $test = array(base64_decode('ZXhwZXJpbWVudA==') => 'example'); ?> Theirfore when its echo'd (ran throught my function) the output would be: <?php $var = "test file"; $var2 = 'example'; $test = array('experiment' => 'example'); ?> My aim is, to replace each base64_decode('string') with 'decodedstring', without effecting the actual file (so only the base64 is replaced).
  18. Thanks, how would i integrate that so it replaces the original encoded with the base64_decoded within the actual file (without placing the decoded in an array)? :-\
  19. Lets say I have a file: <?php $var = "test file"; $var2 = base64_decode('ZXhhbXBsZQ=='); $test = array(base64_decode('ZXhwZXJpbWVudA==') => 'example'); ?> How would i replace each encoded base64 with its decoded (loop it with php?) so it would become: <?php $var = "test file"; $var2 = 'example'; $test = array('experiment' => 'example'); ?> All help is greatly apreciated.
  20. Yeps thats what i was trying to do, - solved it.
  21. How would i preg_replace the space between characters only? For example - before: h e y p h p would turn into: hey php
  22. How would i clear (empty/blank) the contents of a .txt without deleting file? \: I've looked at unlink() but that deletes the file aswell.
  • 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.