Jump to content

Archived

This topic is now archived and is closed to further replies.

wiseguy

String Replacement Question

Recommended Posts

I know very little about php and I'm limited to the basic altering of scripts. I have a script that replaces characters in urls. It stores information in a php file as opposed to a database. Basically it takes a url like http://www.somesite.com and creates a link from it using the url as the link text. What I would like to do is change the function as to where I can create the links with my own link text. Below are the functions used by the script.

$str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',    '<a href="\\1" target="_blank">\\1</a>', $str);
$str = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',    '\\1<a href="http://\\2" target="_blank">\\2</a>', $str);


Share this post


Link to post
Share on other sites
I assume your source file only has the url? Where will the text come from?

Share this post


Link to post
Share on other sites
[quote author=effigy link=topic=107382.msg430827#msg430827 date=1157742762]
I assume your source file only has the url? Where will the text come from?
[/quote]
Thanks for the response.

This is a Q&A script. The source file contains everything including the question text, answer text, and urls. When reading a url from the source the script writes out the link (taken from an entered url) in the form of:
[code]<a href="http://www.somesite.com">http://www.somesite.com</a>[/code]

I want to be able to specify my own link text as in:
[code]<a href="http://www.somesite.com">My Text Here</a>[/code]

Share this post


Link to post
Share on other sites
Change the \\1 at the end: [tt]<a href="\\1" target="_blank">[b]\\1[/b][/tt]

Share this post


Link to post
Share on other sites
[quote author=effigy link=topic=107382.msg430873#msg430873 date=1157747045]
Change the \\1 at the end: [tt]<a href="\\1" target="_blank">[b]\\1[/b][/tt]


[/quote]

That will remove the url as the link text but does not allow me to add my own link text.

Share this post


Link to post
Share on other sites
[quote author=wiseguy link=topic=107382.msg430864#msg430864 date=1157746029]
[quote author=effigy link=topic=107382.msg430827#msg430827 date=1157742762]
I assume your source file only has the url? Where will the text come from?
[/quote]
Thanks for the response.

This is a Q&A script. The source file contains everything including the question text, answer text, and urls. When reading a url from the source the script writes out the link (taken from an entered url) in the form of:
[code]<a href="http://www.somesite.com">http://www.somesite.com</a>[/code]

I want to be able to specify my own link text as in:
[code]<a href="http://www.somesite.com">My Text Here</a>[/code]
[/quote]

And the text you want to specify, is in the source too? give us a sample of your code so we can help you build a matching pattern.

Share this post


Link to post
Share on other sites
[quote]And the text you want to specify, is in the source too? give us a sample of your code so we can help you build a matching pattern.[/quote]

The data is stored in a text file. The script takes whatever you enter as a url and automatically makes that url the link text so you end up with a link like below on a dynamically created page:
[code]<a href="http://www.somesite.com">http://www.somesite.com</a>[/code]

This is the scripts link function:
[code]function convertLinks($str) {
$str = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',    '<a href="\\1" target="_blank">\\1</a>', $str);
$str = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',    '\\1<a href="http://\\2" target="_blank">\\2</a>', $str);
$str = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',    '<a href="mailto:\\1">\\1</a>', $str);
return $str;[/code]

This is an example block from the text file database.
[code]7\¦I have MP3 files of songs I have written, and I would like to convert them to MP3+G format.  How do I create the .CDG file to go with the .MP3 file?  Is there free software to do this?\¦There are several software applications that will allow you to do this. I do not know of any free ones. To find find some of these programs go to http://www.karaoke-software.net/cdg-authoring.html\¦205.167.198.122\¦1155245666\¦1157770737[/code]

I would just like to be able to code a link in my responses without the script rewriting my input.



Share this post


Link to post
Share on other sites

×

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.