Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by newbtophp

  1. Thanks teamatomic and MadTechie! Both worked perfectly!
  2. Hi, Im trying to figure out how to do the following (examples are below), with regex, im guessing i'd have to look forward and back (if thats the correct term) and then replace accordingly. I hope the examples would explain what its meant to be doing, as Im unsure how to explain. :-\ Examples: Input: hello '\';'; Output would become: hello '\'; --------- Input: hello '; '; Output would become: Removed (Replaced with nothing) --------- Input: hello '; Output would become: Removed (Replaced with nothing)
  3. Hi, I need help, Im trying to try and correct a file which contains ';' before echos, however I can't simply just use str_replace, so perhaps manipulate token_get_all or regex? Heres the code (input): <?php require('tops.php'); ;echo '<center><br><br> '; if ($step == '2') { ;echo 'step is two'; } ?> I would like the output to become: <?php require('tops.php'); echo '<center><br><br> '; if ($step == '2') { echo 'step is two'; } ?> PS: I know this may be unreliable, or may not even work in some cases, but was curious as to how it could be done even if it results in this.
  4. I have a site like: domain.com/index.php?del=3554, which when this page is accessed it would delete a file. So I was wondering without me having to visit that url to delete it, is their a way in php to do that for me - i need this since I'd like to delete the file remotely, ie. access that url - so it will delete the file. Anyone can help, i have a few ideas such as cURL, fsockopen? :-\
  5. Anyone can help me? :-\
  6. How would i takeaway 20 as many times as $x from $total ? For example: if $x = 2, and $total was 50, it would output 10. :-\
  7. Anyone? Perhaps changing: header('Content-Transfer-Encoding: binary'); too: header('Content-Transfer-Encoding: base64'); ?
  8. Hmm i have a problem, im encoding a string and writing it to a file, and then downloading it using header() however i want the downloaded file to contain the decoded string (base64_decode), but i need to do this without echoing/printing the decoded output or writing the decoded output anywhere? (like readfile), my code: <?php $file = 'file.txt'; $handle = fopen($file, "w"); fwrite($handle, base64_encode($string)); fclose($handle); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); //decode it in memory without echoing or writing it anywhere... readfile(base64_decode($file)); exit; ?> PS: Cant really explain why i specifically need it to be decoded in memory (so its not echo'd or written anywhere). - as it would be tough to explain. :-\
  9. Im looping through an array of $_FILES using foreach, and then preg_matching that using if else, if found then run a function on that, however when i have more than 1 file and a match is found and the function runs, it outputs a fatal error can not redeclare function error Im not not sure why its doing this since its not the same file... This only happens when more than one file (even though they are different files) call the same function when looping. Here the code: if(count($_FILES["item_file"]['name'])>0) { //check if any file uploaded $GLOBALS['msg'] = ""; //initiate the global message for($j=0; $j < count($_FILES["item_file"]['name']); $j++) { //loop the uploaded file array $file_name = $_FILES["item_file"]['name']["$j"]; //file name $file = file_get_contents($_FILES["item_file"]['tmp_name']["$j"]); if(preg_match("~php~", $file)){ echo php($file); } else if(preg_match("~pl~", $file)){ echo perl($file); } } } } Any can help me, please.
  10. Well my assumption was its impossible, but i had second thoughts regarding this so thought i'd ask the question here. How would i add php tags around php code? (even if its not always accurate). Maybe by manipulating the token_get_all function? Example: function hey($code){ return "hey".$code; } <html> <title>PHPFreaks</title> Would transform into: <?php function hey($code){ return "hey".$code; } ?> <html> <title>PHPFreaks</title> Let me know your thoughts?, and if manipulating token_get_all would work?
  11. how to check if string is gzdeflate compressed? <?php if(/*$string is gzdeflated...*/){ gzinflate($string); } else { //its not compressed } ?>
  12. Solved i just replaced it with file_get_contents
  13. I was wondering i have the following code, where $fp is fopen... (currenting im calling a file, but i no longer want to, i want to embed the files content directly, but fread doesnt seem to work like that): $fd = fread($fp,"28429"); How would i do the same without actually using fopen but instead making the file as a string like: $fd = fread("string....","28429"); I've tried it but it gives errors, is their a way I can use fread or mimic its functionality but on a string? :-\
  14. Im having a bit of trouble on calulating the number of showing search results, if I have 20 search results per page, and page number was 1, it should echo 1-20, if the page number was 2 it would echo 21 - 40, if the page number was 3 it would echo 41 - 60... and soo on. My code; <?php $totalresults = 348; $perpage = 20; $page = 1; ?> :-\
  15. Figured it out!, by copying old array and creating a new array using a forech loop Although if anyone has any simpler/more effective methods please do add.
  16. Thanks figured that aspect out, but got another issue, Say if I have an array like: Array ( [0] => peter-pan [2] => life-death-peter-sellers [4] => peter-and-vandy ) How can I turn it into: Array ( [0] => peter-pan [1] => life-death-peter-sellers [2] => peter-and-vandy ) I've tried sort but that rearrange the grouping, I want the elements to stay in the same place, but ensure that their in numerical order.
  17. I have 2 arrays with the the same amount of elements, i want to loop through them both and then link the titles with the $pages (href location). Currently its not echoing what I expect it too (presumably due to me looping it incorrectly?) Currently its outputting : <a href="life-death-peter-sellers">Peter Pan</a><br> <a href="life-death-peter-sellers">Peter and Vandy</a><br> <a href="life-death-peter-sellers">The Life and Death of Peter Sellers</a><br> <a href="peter-and-vandy">Peter Pan</a><br> <a href="peter-and-vandy">Peter and Vandy</a><br> <a href="peter-and-vandy">The Life and Death of Peter Sellers</a><br> <a href="peter-pan">Peter Pan</a><br> <a href="peter-pan">Peter and Vandy</a><br><a href="peter-pan">The Life and Death of Peter Sellers</a><br> $pages contains: Array ( [0] => life-death-peter-sellers [1] => peter-and-vandy [2] => peter-pan ) $titles contains: Array ( [0] => Peter Pan [1] => Peter and Vandy [2] => The Life and Death of Peter Sellers ) My current code: foreach($pages as $page){ foreach($titles as $title){ echo "<a href=\"".$page."\">".$title."</a><br>"; } } Expected Output: <a href="life-death-peter-sellers">Peter Pan</a><br> <a href="peter-and-vandy">Peter and Vandy</a><br> <a href="peter-pan">The Life and Death of Peter Sellers</a><br> All help is appreciated :-\ :-\
  18. I created a function which i can use instead of mysql_query, which would query aswell as check the time taken for the queries execution, but now was wondering if i could do some sort of if statement to determine if the execution time is higher than the average - than email it. function time_query($query){ $s = microtime(true); $results = mysql_query($query); $e = microtime(true); //not sure whats average... if(round($e - $s, 3) > IS HIGHER THEN AVERAGE){ mail(....); } return $results; }
  19. I've created a function to limit the amount of text according to the amount of words. However it ruins html and bbcode tags.. . I only want it to have affect on everything else within $text but not bbcode & html. Heres the code: <?php function containText($text, $length) { $words= explode(' ', $text); // string to array foreach ($words as $word) { $break = 0; for ($i = 0; $i < strlen($word); $i++) { if ($break >= $length) { $word= wordwrap($word, $length, '-<br>', true); //add <br> every $length chars $break = 0; } $break++; } $newText[] = $word; //add word to array } $text = implode(' ', $newText); //array to string $text = wordwrap($text, $length, "<br />\n"); return $text; } $text = "PHPfreaks is awesome!!!!! Lets Party! [img=http://awesome.gif] <img src=\"image.gif\"> Yay! <a href=\"http://www.phpfreaks.com\">Woot</a> [font=2]BIG![/font]"; print containText($text, 10); ?> :-\
  20. I need some help, in grouping numbers in lots of 15. Im trying to figure out a way to sort an array of numbers in numerical order, then create a new array which will consist of the numbers being in numerical order and have next to them their group number followed by their order number. This is what i expect it to be like: Input: array("26", "29", "27", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45"); Output: Array ( [26] => 1, 1 [27] => 1, 2 [29] => 1, 3 [30] => 1, 4 [31] => 1, 5 [32] => 1, 6 [33] => 1, 7 [34] => 1, 8 [35] => 1, 9 [36] => 1, 10 [37] => 1, 11 [38] => 1, 12 [39] => 1, 13 [40] => 1, 14 [41] => 1, 15 [42] => 2, 1 [43] => 2, 2 [44] => 2, 3 [45] => 2, 4 ) This is so far what I've come up with: <?php $ids = array("26", "29", "27", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45"); //sort them in numerical order... sort($ids, SORT_NUMERIC); print_r($ids); ?> All help is greatly appreciated, as I've tried myself and seems pretty complex :-\ Thanks.
  21. Im alittle lost, Im trying to paginate a little basic php forum I created, so it displays 20 posts per page, and I've added a link to each post so i can scroll down to each post directly. However it doesn't seem to display 20 posts per page, and I can't seem to figure out a way to directly link them on other pages, because theirs no way to tell what page the post is on so I cant simply do topic.php?id=3#456 because I can't be certain post 456 will be on page 1. (if you understand what i mean?). :-\ <?php $topic_id = $_GET['id']; $start = @$_GET['start']; $limit = 15; if(!isset($start)) $start = 0; $sql = mysql_query("SELECT * FROM `site_posts` WHERE `post_topic` = '$topic_id' ORDER BY `post_id` ASC LIMIT $start , $limit"); while ($row = mysql_fetch_array($sql)){ $post_id = $row['post_id']; $post_author = stripslashes($row['post_author']); $post = stripslashes($row['post_body']); //display post - notice the link so i can access a post directly? : D echo $post_author." - <a name=\"{$post_id}\" href=\"#{$post_id}\">".$post."</a><br>"; $sql2 = mysql_query("SELECT * FROM `site_users` WHERE `user_username` = '$post_author'"); while ($row2 = mysql_fetch_array($sql2)){ $user_id = $row2['user_id']; } } $sql = mysql_query("SELECT `post_id` FROM `site_posts` WHERE `post_topic` = '$topic_id'"); $d=0; $f=0; $g=1; print "Page Select: "; while($order3=mysql_fetch_array($sql)) { if($f%$limit==0) { if ($start == $d) { print " $g |"; } else { print " <a href='{$_SERVER['PHP_SELF']}?start=$d&id=$topic_id'>$g</a> |"; } $g++; } $d=$d+1; $f++; } ?> Anyone can help me? :-\
  22. Access it like pagename.php?url=http://omars.gmu.edu/items/show/2536 <?php $url = strip_tags($_GET['url']); if(isset($url)){ $file = file_get_contents($url); preg_match("/<div class=\"element-text\">http:\/\/([a-z0-9\/\.]*)<\/div>/i", $file, $matches); echo $matches[0]; } ?>
  • 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.