473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to make text area recognize hyperlinks?

I built a simple form where a user can enter and post news items to his
site (with PHP, into MySQL). He doesn't know much HTML.

Is there some way he can enter some simple text to declare something a
hyperlink, and have PHP recognize that that means "make this text into a
hyperlink"?

....so that instead of having to type this into the textarea:

<a href="http://www.somesite.com">somesite</a>

....he could type something more intuitive, like this:

<somesite.com>somesite</somesite.com>?

Maybe there's a better way even than I'm explaining. Any help is
appreciated.
--Mike
Jul 17 '05 #1
4 10974
Mike Mella wrote:
....so that instead of having to type this into the textarea:

<a href="http://www.somesite.com">somesite</a>

....he could type something more intuitive, like this:

<somesite.com>somesite</somesite.com>?

Maybe there's a better way even than I'm explaining. Any help is
appreciated.


The easiest to use format is one where you don't get to specify what the
title of the link should be:

<link>http://www.somesite.com</link>

You could also use:

<link somesite.com/www/myfile.php?id=5>Click here</link>

With the format you suggest, you would require:

<somesite.com/www/myfile.php?id=5>Click here to visit
site</somesite.com/www/myfile.php?id=5>

In any case, you should look into regular expressions to parse your links.

For this format:

http://www.mylink.com

You can use the regex I'm using on my forum:

preg_replace(
"/\[url\](.*?)\[\/url\]/i",
"<a href='\\1'>\\1</a>",
$mytext);

Cheers,
Nicholas Sherlock
Jul 17 '05 #2
Nicholas Sherlock wrote:
Mike Mella wrote:
....so that instead of having to type this into the textarea:

<a href="http://www.somesite.com">somesite</a>

....he could type something more intuitive, like this:

<somesite.com>somesite</somesite.com>?


In any case, you should look into regular expressions to parse your links.

For this format:

http://www.mylink.com

You can use the regex I'm using on my forum:

preg_replace(
"/\[url\](.*?)\[\/url\]/i",
"<a href='\\1'>\\1</a>",
$mytext);


There's a lot of 'off the shelf' code to do this kind of thing. phpBB is the
most popular (and its secure for now). Alternatively if you just plonk
something like FCKeditor on the page then it's all done at the browser end
- although you'd probably want to do a lot of parsing of the returned value
to protect against XSS attacks.

Alternatively you might want to look at implementing a Wiki.

HTH

C.
Jul 17 '05 #3
Mike Mella wrote:
I built a simple form where a user can enter and post news items to his
site (with PHP, into MySQL). He doesn't know much HTML.

Is there some way he can enter some simple text to declare something a
hyperlink, and have PHP recognize that that means "make this text into a
hyperlink"?

...so that instead of having to type this into the textarea:

<a href="http://www.somesite.com">somesite</a>

...he could type something more intuitive, like this:

<somesite.com>somesite</somesite.com>?

Maybe there's a better way even than I'm explaining. Any help is
appreciated.
--Mike


Yeah, there is a better way: In this case, it sounds like your client
would very much appreciate using a WYSIWYG textarea editor, such as
TinyMCE: http://tinymce.moxiecode.com/. TinyMCE's a drop-in javascript
replacement compatible with most browsers, and is in fact already used
by many CMS's (such as MamboCMS). Very nice. I've used it to add a touch
of (optional) "class" to my projects.
Jul 17 '05 #4
Hey, that's great, thanks! I've set up TinyMCE and it is better.

I have a question for you since you've used it though -- When I type
something in the text field, TinyMCE automatically enters it between <p>
tags. I would like to change this. I understand that there is a file
somewhere where defaults like that can be edited, but the manual isn't
specific about which one. Can you tell me? I'll post it in the forums,
but I thought I'd ask you first.

Thanks again.
--Mike


Jason F. wrote:
Mike Mella wrote:
I built a simple form where a user can enter and post news items to
his site (with PHP, into MySQL). He doesn't know much HTML.

Is there some way he can enter some simple text to declare something a
hyperlink, and have PHP recognize that that means "make this text into
a hyperlink"?

...so that instead of having to type this into the textarea:

<a href="http://www.somesite.com">somesite</a>

...he could type something more intuitive, like this:

<somesite.com>somesite</somesite.com>?

Maybe there's a better way even than I'm explaining. Any help is
appreciated.
--Mike

Yeah, there is a better way: In this case, it sounds like your client
would very much appreciate using a WYSIWYG textarea editor, such as
TinyMCE: http://tinymce.moxiecode.com/. TinyMCE's a drop-in javascript
replacement compatible with most browsers, and is in fact already used
by many CMS's (such as MamboCMS). Very nice. I've used it to add a touch
of (optional) "class" to my projects.

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Aasp | last post by:
Hello! I'm a complete Javascript newbie and my question is surely very naive, but believe me, I've spent this whole day searching thru the net and didn't find any solution to my little problem....
2
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
19
by: Joe | last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first column contains hyperlinks. When a user clicks one of these hyperlinks, he will navigate to another aspx page (referred...
4
by: Seefor | last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did this which works fine: a, a:link, a:visited, a:hover, a:active { color: #000; text-decoration: none;
3
by: wolfing1 | last post by:
In several of my pages I need to show an area with a background image and HTML text in certain places. The restrictions I have is that I can't use javascript or CSS positioning like 'float', so I...
0
by: ikarkaroff | last post by:
Hi all, We have a legacy application and it contains static text boxes (not the proper windows static text box but just text painted on the window). I want to read this text with my own...
6
by: David Stone | last post by:
I have a simple question about the alt content of area elements within an image map: is it redundant to include phrases such as "link to..." or "jump to..."? My initial thought is 'yes', since...
3
by: harv3yb1rdman | last post by:
Hi, I have a blog which people often include a link in their comment. Can anyone point me to a script or demonstrate how I can automatically surround the text links with an anchor when the...
8
by: Dan Rumney | last post by:
All, I have a web page (copied below) with 3 images on it of fixed dimensions. Each image has a map associated with it In the maps, there are a number of areas with an onClick handler...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.