Explode Option

Started on the old forum in August 2007 · view the original in the archive · old links redirect here

10 replies · 968 views · started 19 years ago · 1 min read

3 participants
learner Lead · 587 posts #1

ok guys i want to know if it is possible to use random text in a url area of ur script? supposing i have this code img src="http:// so instead of addin 1 url there i want to put the images urls in a text file and get them exploded in the http:// area is it possible???? i dont want to use random image

Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

BEST MOBILE ADVERTISER

External image (may be gone)

linkrx7 #2

cant understand what u want lol

darkdesire Senior · 250 posts #4

CODE<?php

$folder = '.';

$extList = array(); $extList['gif'] = 'image/gif'; $extList['jpg'] = 'image/jpeg'; $extList['jpeg'] = 'image/jpeg'; $extList['png'] = 'image/png';

$img = null;

if (substr($folder,-1) != '/') { $folder = $folder.'/'; }

if (isset($_GET['img'])) { $imageInfo = pathinfo($_GET['img']); if ( isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) && file_exists( $folder.$imageInfo['basename'] ) ) { $img = $folder.$imageInfo['basename']; } } else { $fileList = array(); $handle = opendir($folder); while ( false !== ( $file = readdir($handle) ) ) { $file_info = pathinfo($file); if ( isset( $extList[ strtolower( $file_info['extension'] ) ] ) ) { $fileList[] = $file; } } closedir($handle);

if (count($fileList) > 0) {
    $imageNumber = time() % count($fileList);
    $img = $folder.$fileList[$imageNumber];
}

}

if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header ($contentType); readfile($img); } else { if ( function_exists('imagecreate') ) { header ("Content-type: image/png"); $im = @imagecreate (100, 100) or die ("Cannot initialize new GD image stream"); $background_color = imagecolorallocate ($im, 255, 255, 255); $text_color = imagecolorallocate ($im, 0,0,0); imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color); imagepng ($im); imagedestroy($im); } }

?>

create a file called index.php tusing the code above, place it in a folder called logo.gif and also place your random images in this folder, then you just use a standard image link using logo.gif as the image name, this will then randomise the images you place in the folder

Hope this helps

:p:p:p

linkrx7 #5

u only want the filename to randomise rite?

learner Lead · 587 posts #6

yes bro i only want the url part to randomly change not the img src="http:// only the 123.com/xxx.gif only this part i want to change rendomly with some random code

Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

BEST MOBILE ADVERTISER

External image (may be gone)

hellspawn #7

K create a txt file with ur links in like so. for this example will use links.txt

-blah.com/path1/path2/jig.gif -foo.org/path1/path2/dance.jpg

etc. etc. we will use the - to distinguish between the different urls

code is:

<?php
$xfile = @file("links.txt");
$random_num = rand (0,count($xfile)-1);
$udata = explode("-",$xfile[$random_num]);
$link = $udata[1];

echo "<img src=\"http://$link\" alt=\"*\"/>";
?>

Should do it External image (may be gone)

WhiteWarrior Principal · 1,419 posts #10

i think i know what your after lol create a file and call it links.txt cmod to 777 add in there

::<a href=\"YOUR LINK\">LINK NAME</a>
 ::<a href=\"YOUR LINK\">LINK NAME</a>

add as many as you want... then on the page you want to show the random links put

$xfile = @file("links.txt");
$random_num = rand (0,count($xfile)-1);
$udata = explode("::",$xfile[$random_num]);
echo "$udata[1]";

that should work fine and it would flick thru links...... if you want it to show images with the links add this to the links.txt

::<a href=\"YOUR LINK\"><img src=\"images/home.gif\" alt=\"LINK NAME OR LEAVE BLANK\"/></a>

add as many as you like... 🙂 hope it works for ya

learner Lead · 587 posts #11

brother the code works fine but the problem im facing is that sometimes it dont fetch anything from links.txt file it remains blank until u refresh ur index again

Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

BEST MOBILE ADVERTISER

External image (may be gone)

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close