wiseguy Posted September 8, 2006 Share Posted September 8, 2006 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 https://forums.phpfreaks.com/topic/20151-string-replacement-question/ Share on other sites More sharing options...
effigy Posted September 8, 2006 Share Posted September 8, 2006 I assume your source file only has the url? Where will the text come from? Link to comment https://forums.phpfreaks.com/topic/20151-string-replacement-question/#findComment-88611 Share on other sites More sharing options...
wiseguy Posted September 8, 2006 Author Share Posted September 8, 2006 [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 https://forums.phpfreaks.com/topic/20151-string-replacement-question/#findComment-88642 Share on other sites More sharing options...
effigy Posted September 8, 2006 Share Posted September 8, 2006 Change the \\1 at the end: [tt]<a href="\\1" target="_blank">[b]\\1[/b][/tt] Link to comment https://forums.phpfreaks.com/topic/20151-string-replacement-question/#findComment-88651 Share on other sites More sharing options...
wiseguy Posted September 8, 2006 Author Share Posted September 8, 2006 [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. Link to comment https://forums.phpfreaks.com/topic/20151-string-replacement-question/#findComment-88698 Share on other sites More sharing options...
Nicklas Posted September 10, 2006 Share Posted September 10, 2006 [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 https://forums.phpfreaks.com/topic/20151-string-replacement-question/#findComment-89152 Share on other sites More sharing options...
wiseguy Posted September 10, 2006 Author Share Posted September 10, 2006 [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 https://forums.phpfreaks.com/topic/20151-string-replacement-question/#findComment-89157 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.