Welcome to Geeklog, Anonymous Wednesday, January 15 2025 @ 03:12 am EST
Geeklog Forums
links that contain '#'
I ran into a peculiar thing today with geeklog stories. Geeklog has a feature that extracts all links out of a story and lists them at the bottom under a heading "What's related". I really like the feature. However, today I posted a story that contains a table of contents using internal links. The syntax for these links is
<a href='#label'>some text</a>
So, I had about a dozen of these showing up in the "What's related" list. UGH!
So, I located the code that builds the list and added a line to skip links that contain a '#'.
Obviously, this is a short term fix. There is a problem with what to do with legitimate links that contain a '#'. I probably won't want to skip those.
For now, here's my fix. I changed file lib-story.php, function STORY_extractLinks().
//Jim Barrett
//2006-02-01
//I need to exclude href that contains '#' within my url
//so, testing if link contains a '#'
//if no, save it, else skip it.
//TODO: what if I link to someone else's site and it contains a '#'?
//I will need to a way to test if my site or not.
if(stristr($matches[1][$i], '#') === FALSE) {
$rel[] = '<a href="' . $matches[1][$i] . '">'
. str_replace ("/(\015\012)|(\015)|(\012)/", '', $matches[2][$i])
. '</a>';
}
Jim
Text Formatted Code
<a href='#label'>some text</a>
So, I had about a dozen of these showing up in the "What's related" list. UGH!
So, I located the code that builds the list and added a line to skip links that contain a '#'.
Obviously, this is a short term fix. There is a problem with what to do with legitimate links that contain a '#'. I probably won't want to skip those.
For now, here's my fix. I changed file lib-story.php, function STORY_extractLinks().
Text Formatted Code
//Jim Barrett
//2006-02-01
//I need to exclude href that contains '#' within my url
//so, testing if link contains a '#'
//if no, save it, else skip it.
//TODO: what if I link to someone else's site and it contains a '#'?
//I will need to a way to test if my site or not.
if(stristr($matches[1][$i], '#') === FALSE) {
$rel[] = '<a href="' . $matches[1][$i] . '">'
. str_replace ("/(\015\012)|(\015)|(\012)/", '', $matches[2][$i])
. '</a>';
}
Jim
8
8
Quote
Status: offline
rasher
Forum User
Newbie
Registered: 03/21/04
Posts: 12
Quote by xucaen:There is a problem with what to do with legitimate links that contain a '#'. I probably won't want to skip those.
try this if statement instead.
Text Formatted Code
if ( ! ereg ("^#", $matches[1][$i]) )This just says, if $matches does NOT start with a # then continue.
It would allow anything that didn't have a # as the first character through.
6
7
Quote
Status: offline
xucaen
Forum User
Junior
Registered: 01/08/06
Posts: 24
try this if statement instead.
This just says, if $matches does NOT start with a # then continue.
It would allow anything that didn't have a # as the first character through.
Text Formatted Code
if ( ! ereg ("^#", $matches[1][$i]) )This just says, if $matches does NOT start with a # then continue.
It would allow anything that didn't have a # as the first character through.
Hi, Thanks!
Jim
6
6
Quote
All times are EST. The time is now 03:12 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content