Jump to content

adrianTNT

Members
  • Posts

    146
  • Joined

  • Last visited

Posts posted by adrianTNT

  1. Hello, I have a function that is supposed to loop over a given directory and remove all its sub files AND folders.

    The problem is... in some situations it crashes the server, I think it does an infinite loop. I know that it does this when I have MAC files in that folder, whenever this happens I always have a sub folder named "__MACOSX" and inside that folder there are files starting with "._", like ._photo.jpg

     

    Can someone please tell me how to fix ths function? It probably has something to do with area $child[0] == '.'

    Or maybe cause is that directory is never closed back, I dont know where to close it (not my code) :(

     

    	// remove all contents of the directory
    function rmdir_r($path) {
      if (!is_dir($path)) {return false;}
      $stack = Array($path);
      while ($dir = array_pop($stack)) {
    	if (@rmdir($dir)) {continue;}
    	$stack[] = $dir;
    	$dh = opendir($dir);
    	while (($child = readdir($dh)) !== false) {
    	  if ($child[0] == '.') {continue;}
    	  $child = $dir . DIRECTORY_SEPARATOR . $child;
    	  if (is_dir($child)) {$stack[] = $child;}
    	  else {unlink($child);}
    	}
      }
      return true;
    }
    rmdir_r('temp2');

     

    Thank you.

  2. Hello, I have a function that is supposed to loop over a given directory and remove all its sub files AND folders.

    The problem is... in some situations it crashes the server, I think it does an infinite loop. I know that it does this when I have MAC files in that folder, whenever this happens I always have a sub folder named "__MACOSX" and inside that folder there are files starting with "._", like ._photo.jpg

     

    Can someone please tell me how to fix ths function? It probably has something to do with area $child[0] == '.'

     

    	// remove all contents of the directory
    function rmdir_r($path) {
      if (!is_dir($path)) {return false;}
      $stack = Array($path);
      while ($dir = array_pop($stack)) {
    	if (@rmdir($dir)) {continue;}
    	$stack[] = $dir;
    	$dh = opendir($dir);
    	while (($child = readdir($dh)) !== false) {
    	  if ($child[0] == '.') {continue;}
    	  $child = $dir . DIRECTORY_SEPARATOR . $child;
    	  if (is_dir($child)) {$stack[] = $child;}
    	  else {unlink($child);}
    	}
      }
      return true;
    }
    rmdir_r('temp2');

     

    Thank you.

  3. I already have many "user comments" in database and Is best to find a good way to display those instead of using something like BB code.

     

    Maybe somone can tell me how to apply a htmlentities on text outside of the <a> tags for this function?

    How can I do a htmlentities($1) and htmlentities($2) for this code?

     

    <?php 
    // converts links inside plain text to clickable <a> tags
    if (!function_exists("text_to_clickable_link")) {
    function text_to_clickable_link($text){ 
    	# this functions deserves credit to the fine folks at phpbb.com 
    	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "$1:", $text); 
    
    	// pad it with a space so we can match things at the start of the 1st line. 
    	$ret = ' ' . $text; 
    
    	// matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing 
    	// Must contain at least 2 dots. xxxx contains either alphanum, or "-" 
    	// zzzz is optional.. will contain everything up to the first space, newline, 
    	// comma, double quote or <. 
    	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "$1<a href=\"http://$2\" rel=\"nofollow\" target=\"_blank\">$2</a>", $ret); 
    
    	// Remove our padding.. 
    	$ret = substr($ret, 1); 
    	return $ret; 
    } 
    }
    ?>
    

  4. Hello, I did a search, I didn't find something similar...

    I need a function, maybe someone can help.

     

    I need to display a user comment (just like a forum post) and

     

    - convert the plain text into a clickable html link

    - do wordwrap on the visible text but not inside the link tag

    - do a htmlentities or htmlspecialchars on the text outside of the link

     

    This is exactly how Vbulletin posts are processed, liks are clickable and text is wrapped properly to avoid long texts that break site layout.

    Anyone can help? I am sure some people used this in websites.

    Thanks.

     

  5. I think with XMLWriter I would have to code the whole page differently.

    I tried some more things and it appears to work ok like this:

     

    $listing_title = $row_Recordset_listings_rss['listing_title'];

    $listing_title = strip_tags($listing_title);

    $listing_title = str_replace("\r\n"," ",$listing_title);

    $listing_title = htmlspecialchars($listing_title);

    $listing_title = utf8_encode($listing_title);

     

    Using htmlspecialchars to get rid of the errors generated by characters like "&".

    So apparently it works ok now.

    Thank you for your time.

     

    - Adrian.

  6. Hello, the tables show latin1_swedish_ci as "collation" and the same in an upper level; I don't know if is correct or not. (These should be the default values that php my admin shown me when setting the database).

     

    I later saw that I had an html_entities() done on the image_title and that was what caused the error I mentioned above in first post. I removed the html_entities() and did this:

     

    $image_title = strip_tags($image_title);
    $image_title = str_replace("\r\n"," ",$image_title);
    $image_title = utf8_encode($image_title);
    

     

    But when it reaches an '&' it says:

    Whitespace is not allowed at this location. Error processing resource 'feed.xml'. Line 1353, Positio...
    <description>Mother & daughter Golden Retriver's Molly & Elsie 
    

     

    Do you know what I should do about this?

    Should I just str_replace the '&' with something like 'and' or there is a more professional fix to avoid this?

     

    Thanks.

  7. Hello.

     

    I have some issues understanding special characters and how they should be printed on screen.

    For example... php takes from database an image title and it is: "Brasão" with that special "a".

    In the web page it is printed correctly but inside an rss (feed file that I made) it says:

     

    The XML page cannot be displayed

    Reference to undefined entity 'Atilde'. Error processing resource 'http://www.jpgbox.com/feed.xml'. Line 76, Position 16

    <title>Brasão Rio Grande do Sul</title>

    ---------------^

     

    Is there a function that I can use to convert the string to be safely printed in the RSS file?

    In my rss header I have application/rss+xml charset:utf-8.

    I hope I explained correctly.

     

    Thank you.

    - Adrian.

     

  8. Hello, I have a code that creates <a> tags (clickable links) from plain text urls. This code searches for http:// and www and creates the <a> tags.

     

    $ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" rel=\"nofollow\" target=\"_blank\">\\2</a>", $ret);

     

    How can I truncate the \\2 before the </ a>? So that it doesn't break my layout. I have a truncate_text() function but I don't know how to insert it there.

     

    Thank you.

     

  9. I managed to do it by count(DISTINCT user_id) FROM table_name, it returns correct results but it looks buggy to me, is this correct?

     

    // total unique users subscribed to at least one category 
    mysql_select_db($database_cms, $cms);
    $query_Recordset_stats_unique_subscribers = "SELECT count(DISTINCT cat_subscription_user_id) FROM cat_subscriptions";
    $Recordset_stats_unique_subscribers = mysql_query($query_Recordset_stats_unique_subscribers, $cms) or die(mysql_error());
    $row_Recordset_stats_unique_subscribers = mysql_fetch_assoc($Recordset_stats_unique_subscribers);
    $totalRows_Recordset_stats_unique_subscribers = mysql_num_rows($Recordset_stats_unique_subscribers);

     

    I have "count" there in 2nd line but in order to return the total is this line correct? Do I use count distinct again?

     

    <?php echo $row_Recordset_stats_unique_subscribers['count(DISTINCT cat_subscription_user_id)']; ?>

     

    It is the second code that looks buggy, I am not sure the thing inside the [] is correct, it does return the correct results but I was expecting it to return the total by: $totalRows_Recordset_stats_unique_subscribers

    Is it correct?

  10. Hello, can someone tell if there is a commend for this?

     

    I have a table that has fields like:

     

    ID        CATEGORY ID        USER ID

    -----+----------------+-------------

    0                10                25

    1                12                24

    2                9               24

    3                20                25

     

    (The table represents users subscribed to categories).

    User id can be more than once in the table, I want to find the total number of users subscribed to categories, in the above sample this total would be 2 (user 24 and user 25).

    I think the command (if exists) should be something like: "count total unique values of USER ID from TABLE_NAME" ?

     

    Any ideas?

    Thanks.

  11. Hello.

     

    I am trying to put watermarks on images on-the-fly by a php script, in general this is done by merging two images , the source and a watermark (usually PNG with transparency).

     

    The problem is ... I cannot get the right combination (jpg/png, 8/16 bits, indexed color/RGB color) in order for the watermark to appear with smooth edges over the source image, the watermark always appears eider with white opaque background or when it is transparent it has rough edges.

     

    Any advices?

    Thank you.

  12. Your code works fine for me.

    Did you add an empty line or space before sending the header?

    It works now.

    No spaces when I tested but today it works fine, it was a cache issue.

     

    You want it to show the contents of the file, like a feed?  I have experience with this as I created a generator that would create an xml feed from the contents of the news table in my database.

    Yes, something like that, but the problem now was the header info to tell browsers to treat it like an XML file, I will now see if it works to dinamically generate the tags, this part should not be a problem.

    Thank you both for your time.

  13. Hello, I want to generate a feed file dynamically inside a .php file, but in my browser it looks like a plain file even if the source file contains the right tags, I simplified it to this code (attached), is the header info incorrect or why does the browser read it like a plain file?

     

    <?php header ("content-type: text/xml");?>
    <?php echo html_entity_decode('<?xml version="1.0" encoding="UTF-8" ?>');?> 
    <rss VERSION="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
       <channel>
           <item>
           <title>Pong</title> 
           <link>http://www.site.com/flash/games/pong_1327.html</link> 
           <description>Flash Ping-Pong game.Just my version of one of the first games.</description> 
           </item>
           <item>
           <title>RSS reader</title> 
           <link>http://www.site.com/flash/web_applications_and_data/rss_reader_1326.html</link> 
           <description>RSS reader in AS2, uses shared object to save the address if u want</description> 
           </item>
       </channel>
    </rss>

    I can make it physically save an XML file but I prefer to show the xml contents in the php file.

    Any ideas?

    Thanks.

  14. I have this code, the strpos in the function should return false when string is not found, correct? But instead it seems to return false for found string?

    What am I soing wrong?

    I can use the code like this too but it looks worong.

    <?php
    function check_referer($the_referer_to_check){
    // list of urls to remove from referers list when reading the list of referers
    $bad_referers = array('yahoo','google','.mail.live.com','search.msn','abv','google.de','google.se');
    for($i=0;$i<count($bad_referers);$i++){
    	// if string not found then value is FALSE, correct?
    	// so why does it return values for *found values?
    	if(strpos($the_referer_to_check, $bad_referers[$i]) == 'FALSE'){
    		echo $bad_referers[$i].' NOT found in ' .$the_referer_to_check.'<br>'; 
    		}
    }
    }
    
    check_referer('google.com');
    check_referer('site.com'); // this one is not in the bad_referers
    check_referer('abv.bg');
    ?>

     

    Returns:

    google NOT found in google.com

    abv NOT found in abv.bg

×
×
  • 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.