newbtophp
-
Posts
631 -
Joined
-
Last visited
Posts posted by newbtophp
-
-
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
-
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.
-
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 :/
-
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.
-
Im having alittle trouble:
[A-Za-z]
I have the above regex to match letters, however they dont match special character letters like:
ÿ
-
You may also find this useful:
http://www.phpguru.org/downloads/PCRE%20Cheat%20Sheet/PHP%20PCRE%20Cheat%20Sheet.pdf
-
Do you really need a regular expression?
$variable = str_replace(";echo '\n';", "?>\n<?php", $variable);
(If the string contains \r\n style newlines, use that instead of just \n.)
Thanks mate!!
works perfect.!
-
My try - altough no luck:
$variable = preg_replace("#;echo '[\s]';#", "?>\r\n<?php", $variable);
-
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; ?>
:-\
-
Do you need the pattern matching capabilities of regular expressions or would basic string functions work for you? See strstr.
echo strstr($code, 'error_reporting(E_ALL ^ E_NOTICE);');
Both would work - equally fine in this case.
Thanks for that, strstr() is pretty nifty
-
Thanks Jay and Brandon!
Perfect!
-
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', '');
:/
-
Thanks Alex and Salathe!
Salathe, the info was very useful, really appreciate it !
-
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
-
Neil's offline, i dont want to sound rude, but can possibly someone else take alook at this in the mean time?
-
-
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."; } }
-
Does not make sense. Please elaborate.
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).
-
By creating a new array
<?php $test = array('ZXhwZXJpbWVudA==' => 'example'); $new = array(); foreach($test as $key => $val) { $new[base64_decode($key)] = $val; } print_r($new); ?>
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)? :-\
-
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.
-
You could possibly replace all instances of only single spaces using look ahead/behind to ensure it is only a single space if thats what your after.
Yeps thats what i was trying to do, - solved it.
-
How would i preg_replace the space between characters only?
For example - before:
h e y p h p
would turn into:
hey php
-
Thanks Alex!
lol theirs me thinking complex
-
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.
PHP rating
in PHP Coding Help
Posted
I followed your example and some of the scores produce wild numbers such as:
4.8888888888889/5
Which makes it destroy my layout structure. :-\