Jump to content

String Replacement Question


wiseguy

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);


Link to comment
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]
Link to comment
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.
Link to comment
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.



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.