Jump to content


Photo

String Replacement Question


  • Please log in to reply
6 replies to this topic

#1 wiseguy

wiseguy
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 08 September 2006 - 07:06 PM

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




#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 08 September 2006 - 07:12 PM

I assume your source file only has the url? Where will the text come from?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 wiseguy

wiseguy
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 08 September 2006 - 08:07 PM

I assume your source file only has the url? Where will the text come from?

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:
<a href="http://www.somesite.com">http://www.somesite.com</a>

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


#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 08 September 2006 - 08:24 PM

Change the \\1 at the end: <a href="\\1" target="_blank">\\1


Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 wiseguy

wiseguy
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 08 September 2006 - 09:47 PM

Change the \\1 at the end: <a href="\\1" target="_blank">\\1



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

#6 Nicklas

Nicklas
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • Locationwww.nswardh.com

Posted 10 September 2006 - 01:46 AM

I assume your source file only has the url? Where will the text come from?

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:
<a href="http://www.somesite.com">http://www.somesite.com</a>

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


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.

#7 wiseguy

wiseguy
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 10 September 2006 - 02:19 AM

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.


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:
<a href="http://www.somesite.com">http://www.somesite.com</a>

This is the scripts link function:
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;

This is an example block from the text file database.
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

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








0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users