/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Automatically make string into a link?

Hello All,
Okay so how do I make php search through a $_POST[variable] for a certain set of string, lets say R1000000.* Then I would want to turn that string (R1000000) into a link

[code]<a href=example.php?id=”R1000000″>R1000000</a>[/code]

Then append that link back into the original $_POST[variable] replacing the text version(R1000000), with the link version (<a href=example.php?id=”R1000000″>R1000000</a>. I’m not asking for someone to do this for me, just some guidance would be great!
Thank you!!

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogApr 08.2007 — [url=http://www.php.net/preg_replace]preg_replace[/url]() if looking for general string patterns, or [url=http://www.php.net/str_replace]str_replace[/url]() if looking for specific strings.
Copy linkTweet thisAlerts:
@christo16authorApr 08.2007 — Thanks for the reply,

I am having trouble getting the preg_replace to work, is there a good tutorial out there or do you have any ideas?

Thanks!
Copy linkTweet thisAlerts:
@NogDogApr 08.2007 — Suppose you're looking for "version(xxxxx)" where the x's could be any letter or number (e.g.: R00000001), and you want the value within the parentheses to be a link:
[code=php]
$text = preg_replace(
'/(version()([a-zA-Z0-9]+))/i',
'\1<a href="example.php?id=\2">\2</a>)',
$text
);
[/code]

[i]Warning: untested[/i]
Copy linkTweet thisAlerts:
@christo16authorApr 08.2007 — Thank you,

This is what worked for me,
[code=php] $entry_mod = preg_replace("/R[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]b/",
"<a href=example.php?id=$0>$0</a>", $_POST["entry"]);
[/code]
Copy linkTweet thisAlerts:
@JayMApr 08.2007 — Just a quick note: Instead of typing [0-9] so many times you can just type [0-9]{X} where X is the number of times you want a digit.
×

Success!

Help @christo16 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...