Jump to content

pufferz

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

pufferz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks very much for the help! I was able to successfully integrate the code into my plugin. However I have another unforseen problem that someone here might be able to help me with. I want to remove paintext URLs that are inside of posts. Ex. "Hey check out this video! www.video.com" ----> "Hey check out this video! [link removed] Is this possible using regex?
  2. Hi, I'm still a newbie PHP coder but am making a wordpress plugin that removes all links in a post. The way I parse for the links right now it by using simple string manipulation but I have heard that regex would be a far more flexible than this. So my question: How can I use regex to identify and remove the anchor tags and hyperlink, but keep the anchor text intact? Any help would be appreciated
  3. Update! Success...apparently directory names are case sensitive in PHP? Who knew?
  4. Nifty. Using the code provided on that page: <?php // current directory echo getcwd() . "\n"; chdir('cvs'); // current directory echo getcwd() . "\n"; ?> the myblog.com page 'echos' out as: /home/www/myblog.com /home/www/myblog.com and the myblog.com?page_id=11 'echos' out as: /home/www/myblog.com /home/www/myblog.com Unfortunately, it looks as though I'm working in the same directory. So theoretically, shouldn't the scripts work in precisely the same manner? I'm quite baffled here :-\ The only difference that I can find is '?page_id=11' appended to all of the peripheral pages. Also, is there a reason why I hardcoding the HTTP path to the directory isn't working? Shouldn't passing a request to fetch a directory work the same way as a request to fetch, say, and image?
  5. We'll I do consider myself a pretty silly guy. Thanks for the advice though. This is the first thing I ever coded in PHP...and after this experience, hopefully my last ...I'll stick with my hard coded languages. I was pretty proud of my additions to the code though! But again, thanks for the advice. Hopefully I'll be able to get this working soon. Some developments and speculations: I have a feeling my problem lies with the file privileges of the pages of my blog. My home page, where the script actually works, is probably in the root of my webhost. However, my peripheral pages seem to have altering PHP parameters attached to them (?page_id=11 are PHP parameters if I'm not mistaken). Unfortunately, I have absolutely no idea how to solve this problem them...aren't www.myblog.com and www.myblog.com?page_id=11 technically the same page, with equivalent file permissions?
  6. I'm trying to implement the provided script into a wordpress blog. I'm using execPHP to allow me to use PHP inside of the pages of the blog. The script will take a directory name, then randomly select 6 pictures from that directory and outputs the HTML to display those images. The script works perfectly for the home page of my blog but when I try to apply it to one of the peripheral pages it will not display, even if I point them to the same directory. This is the first segment, placed at the top of the blog: <?php function getRandomFromArray($ar) { mt_srand( (double)microtime() * 1000000 ); $num = array_rand($ar); return $ar[$num]; } function getImagesFromDir($path) { $images = array(); if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // checks for gif, jpg, png if ( preg_match("/(\.gif|\.jpg|\.png)$/", $img_file) ) { $images[] = $img_file; } } closedir($img_dir); } return $images; } ?> And then this segment is placed where I need the pictures: <?php $path = 'Images/'; $imgList = getImagesFromDir($path); $img = getRandomFromArray($imgList); $img2 = getRandomFromArray($imgList); $img3 = getRandomFromArray($imgList); $img4 = getRandomFromArray($imgList); $img5 = getRandomFromArray($imgList); $img6 = getRandomFromArray($imgList); echo"<img src=\"" . $path . $img . "\" alt=\"Wallpaper Preview\" />"; echo"<img src=\"" . $path . $img2 . "\" alt=\"Wallpaper Preview\" />"; echo"<img src=\"" . $path . $img3 . "\" alt=\"Wallpaper Preview\" />\n"; //break echo"<img src=\"" . $path . $img4 . "\" alt=\"Wallpaper Preview\" />"; echo"<img src=\"" . $path . $img5 . "\" alt=\"Wallpaper Preview\" />"; echo"<img src=\"" . $path . $img6 . "\" alt=\"Wallpaper Preview\" />"; ?> So for example, if I call the script at www.myblog.com it works, but if I try to call it at www.myblog.com/?page_id=11 it doesn't. Even when I hard code the path to the directory, such as http://www.myblog.com/images/summerphotos/ it won't work (for either page actually). All help would be greatly appreciated! I've been stuck on this seemingly simple project for almost two days now, and I'd like to get moving again
  7. Basically, all I want to do is call the script and then display the image that it returns. So something like this...but not this since its not working <html> <head> </head> <body> <src="Random.php" img src="<?php previewImage('thumb')?>" alt="Preview of Images"/> </body> </html> Also, would anyone mind skimming over the code to make sure its working/corrent? I don't want to disregard a solution because the code is cippled
  8. I have the following php script that was taken from http://ma.tt/scripts/randomimage/ . I want to use this extensively in an HTML page so I turned the script into a basic function so I could add a parameter to it, as to make it more flexible. My question is, now that I edited the parameter into the script, how can I specify this parameter within the HTML page? Heres the Script: <?php function previewImage($directory){ $folder = $directory; // Space seperated list of extensions, you probably won't have to change this. $exts = 'jpg jpeg png gif'; $files = array(); $i = -1; // Initialize some variables if ('' == $folder) $folder = './'; $handle = opendir($folder); $exts = explode(' ', $exts); while (false !== ($file = readdir($handle))) { foreach($exts as $ext) { // for each extension check the extension if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive $files[] = $file; // it’s good ++$i; } } } closedir($handle); // We’re not using it anymore mt_srand((double)microtime()*1000000); // seed for PHP < 4.2 $rand = mt_rand(0, $i); // $i was incremented as we went along header('Location: '.$folder.$files[$rand]); // Voila! } ?>
×
×
  • 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.