...

View Full Version : Convert URL to text link



robchelle2
12-14-2003, 08:07 PM
How do I convert the URL link into a text link in php? Please help! I spent hours and hours trying to figure it out. I've made some progress, but not what I need.

Right now I've modified the script I'm using (PHP Slideshow) to include a linked version of the url (ex.: http://www.bahiyahthemagazine.com/features/features.php) but instead of a long URL I just want a simple text link (ex.: ...more (http://www.bahiyahthemagazine.com/features/features.php)).

The link is constructed from a flat text file that also includes the image description, so the text file looks like:

sistas.png;bahiyah<br> sistahs http://www.bahiyahwomanmagazine.com
reading.png;woman reading http://www.bahiyahwomanmagazine.com/money.htm

I want each slide's descriptions "...more" to link to a different url

Please Help!

----------
One more thing....I also need to be able to specify the 'target'.
----------
==============================================
Here's the code:

<?php


// some formatting options...
$top_row_color = "";
$image_row_color = "";
$bottom_row_color = "";
$page_background_color = "#ebdcd0";
$main_table_border_color = "";
$img_border_color = "#000000";
$main_table_width = "100%";
$home_link = "HOME";
$next_alt = "Next";
$back_alt = "Back";


// set this to true to display the image filename
$show_image_name = "false";

// set to true to display navigation icons instead of text...
$show_navigation_buttons = "true";
$back_button = "http://www.bahiyahthemagazine.com/images/back.gif";
$next_button = "http://www.bahiyahthemagazine.com/images/next.gif";

// automated slideshow options
// set this to true to enable the auto slideshow feature
$auto_slideshow = "false";
// $sec is number of seconds between slides...
$sec = "30";

// set standalone to false if you are using this script in an existing php doc
// e.g. insert the following line in the page where
// you want phpslideshow to appear
// include("phpslideshow.php");
// dont forget to remove the comment slashes...
$standalone = "true";

// file containing optional image descriptions
$pic_info_file="pics.txt";

// name of file containing optional page headings
$heading_info_file = "heading.txt";



################################################################################
// grab the variables we want set for newer php version compatability
// the @ supress the error messages if your php.ini error level is too high
@$currentPic = $GLOBALS['HTTP_GET_VARS']['currentPic'];
@$directory = $GLOBALS['HTTP_GET_VARS']['directory'];

// check for platform dependent path info... (for windows and mac OSX)
$path = empty($HTTP_SERVER_VARS['PATH_INFO'])?
$HTTP_SERVER_VARS['PHP_SELF']:$HTTP_SERVER_VARS['PATH_INFO'];

// a little security - check that the user did not change the path...
// the path may not contain .. or : (as in c:) or start with / (root dir)
if (preg_match(':(\.\.|^/|\:):', $directory)) {
print "<b>ERROR:</b> Your request contains an invalid path.<br>";
print "For security purposes, you can only access directories ";
print "within this one.<br>";
print "Your dir path may not contain .. or : or start with a /<br>";
print "<br><a href=\"$path\">Try again</a>";
exit;
}

// set directory
if (empty($directory)) $directory = ".";

// if there is no $heading_info_file (see format above) set page heading here
if ( !file_exists("$directory/$heading_info_file")) {
$header = "Bahiyah Features";
$browser_title = "$header";
}
else {
$heading_info = file("$directory/$heading_info_file");
$header = htmlentities($heading_info[0]);
}

// image / text buttons
if ($show_navigation_buttons == "true") {
$back_src = "<img src=\"$back_button\" alt=\"$back_alt\" border=\"0\">";
$next_src = "<img src=\"$next_button\" alt=\"$next_alt\" border=\"0\">";
}
else {
$back_src = "<b>$back_alt</b>";
$next_src = "<b>$next_alt</b>";
}

if ( !file_exists("$directory/$pic_info_file")) {
$dh = opendir( "$directory" );
while( $file = readdir( $dh ) ) {
// look for these file types....
if (eregi("(jpg|jpeg|gif|png|swf)$",$file)) {
$pic_info[] = $file;
sort( $pic_info );
}
}
}
else $pic_info=file("$directory/$pic_info_file");

// begin messing with the array
$number_pics = count ($pic_info);
if (empty($currentPic)) $currentPic = 0;
if (($currentPic > $number_pics)||($currentPic == $number_pics))
$currentPic = '0';
$item = explode (";", $pic_info[$currentPic]);
$last = $number_pics - 1;
$next = $currentPic + 1;
if ($currentPic > 0 ) $back = $currentPic - 1;
else $currentPic = "0";

// print the description if it exists
$blank = empty($item[1])?'&nbsp;':htmlentities($item[1]);
// a hack so that you can include <br> tags in the comments...
$blank = ereg_replace ("&lt;br&gt;", "<br>", $blank);



$blank = preg_replace( "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\">\\0</a>", $blank );


$show_name = ($show_image_name=="false")?'&nbsp;':htmlentities($item[0]);

if ($currentPic > 0 ) $nav=$back;
else $nav=$last;

// meta refresh stuff for auto slideshow...
if ($auto_slideshow == "true") {
$meta_refresh = "<meta http-equiv=\"refresh\" content=\"";
$meta_refresh .= "$sec;url=$path?directory=$directory&currentPic=$next\">";
}
else $meta_refresh = "\n";

################################################################################

// top of html page stuff
// print the page header if in standalone mode
if ($standalone == "true") {
print <<< HERE

<html>
<head>
$meta_refresh
<title>$header</title>
<style type="text/css">
body { font-family: arial; font-size: 8px; }
td { font-family: arial; font-size: 8px; }
a { font-family: arial;
font-size: 8px;
text-decoration: none }
</style>
</head>
<body bgcolor="$page_background_color">

HERE;
}

// draw the main table in html
print <<< HERE

<center>

<table width="$main_table_width" align="center" valign="center"
border="0" cellspacing="0" cellpadding="0" bgcolor="$main_table_border_color">
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="left" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top"><font size="2">$blank</font></td>
</tr>
</table>
</td>
<td align="right"><font size="1"><a href="$path?directory=$directory&currentPic=$next">
<img src="$directory/$item[0]" alt="image" border="1"
style="border-color: $img_border_color">
</a></font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center" valign="middle"><a href="$path?directory=$directory&currentPic=$nav">$back_src</a>
[ $next of $number_pics ]
<a href="$path?directory=$directory&currentPic=$next">$next_src</a></td>
</tr>
</table>
</center>
HERE;

// print the page footer if in standalone mode
if ($standalone == "true") {
print <<< HERE
</body>
</html>
HERE;
}

?>

firepages
12-14-2003, 11:58 PM
most probably this line ...



<?
$blank = preg_replace( "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\">...more</a>", $blank );
?>

robchelle2
12-15-2003, 12:07 AM
Originally posted by firepages
most probably this line ...



<?
$blank = preg_replace( "/(?<!<a href=\")((http|ftp)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\">...more</a>", $blank );
?>


No, that didn't work. I get an error saying...

Warning: Unknown modifier '/' in /home/bahiyah/public_html/features/features.php on line 233

firepages
12-15-2003, 12:51 AM
sorry thats a) the forum stripping the backslashes and b)me not checking ..

in that line change


"<a href=\"\\0\">\\0</a>"
for
"<a href=\"\\0\">more</a>"

robchelle2
12-15-2003, 01:12 AM
Thank you soooo much! It works....

One more problem. I'm using this in an iframe, and I want to be able to specify the 'target' for the link....can you help me with that?

robchelle2
12-15-2003, 01:21 AM
Never mind. I just figured it out myself playing around with it. All the slashes make things look so confusing, but I got it.

Thanks again!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum