Hi. Maybe someone can help me here. I think I need to use preg_replace, but I am not positive how to do this.
I have a site that isn't live yet, allfreecruit.com, that posts jobs to about 100 sites. Even though we ask not to post a direct link or email address in the job description, employers will do it anyways. The job will be posted to other job sites, like hotjobs.com, flipdog.com, etc. Before the job is posted to these jobboards, I will want to be able to search the job description and replace any link or email address with a link back to the job posted on AllFreecruit. So for example, if this is the job description:
Searching for a job in the design field? Please visit our site for the job listing at http://www.fakeurl.com
I would want to replace http://www.fakeurl.com with http://www.allfreecruit.com/jobid=1.html
so the job would look like this:
Searching for a job in the design field? Please visit our site for the job listing at http://www.allfreecruit.com/jobid=1.html
Could anyone help me out with this, I need some help coding this but I am having problems figuring it out.
Thanks.
Rachel
interesting problem with preg_replace
Moderator: General Moderators
First, in this type of situation, I would recommend verifying each job entry by hand that comes in.
I could just as easily tell a person where to go by typing in the hexidecimal codes for the URL's, which would show up in the browser as intended, parsed, and readable.
For your purposes, you can use something like what is shown here:
http://www.faqts.com/knowledge_base/vie ... /245/fid/7
I could just as easily tell a person where to go by typing in the hexidecimal codes for the URL's, which would show up in the browser as intended, parsed, and readable.
For your purposes, you can use something like what is shown here:
http://www.faqts.com/knowledge_base/vie ... /245/fid/7
Let me know what you think.Nathan Wallace
Michael Stearne
The following regular expression will replace all URL's in a string
($msg) with working links.
$msg = eregi_replace(
"(http|https|ftp)://([[:alnum:]/
+-=%&:_.~?]+[#[:alnum:]+]*)",
"<a href="\1://\2" target="_blank">\1://\2</a>",
$msg);
Note that this regular expression allows for URL's to extend over more
than one line (
). In some cases you might like to remove this
capability since if the URL finishes exactly at the end of a line and
there are no spaces before the next word that word will be enabled. For
example, "Enabled" below will be part of the links when
is included.
Line breaks are denoted with <CR>.
http://www.somewhere.com<CR>
<CR>
Enabled