/    Sign up×
Community /Pin to ProfileBookmark

How would I get the value of a part of a string?

I have a blog. After someone makes a post, I want to be able to get all the links in the post, alter them, and put them back. How would I do that?

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiJul 03.2010 — I would use the DomDocument class.
Copy linkTweet thisAlerts:
@narutodude000authorJul 03.2010 — I was thinking maybe regex?
Copy linkTweet thisAlerts:
@YelgnidrocJul 03.2010 — I'd say regex
Copy linkTweet thisAlerts:
@MindzaiJul 04.2010 — Why would you use regex when DomDocument is purpose built for exactly this kind of task? There are just too many variables involved with matching HTML tags.
Copy linkTweet thisAlerts:
@YelgnidrocJul 04.2010 — There are just too many variables involved with matching HTML tags.[/QUOTE]

Where did html tags come from?

OP was about links (hyperlinks I assume)
Copy linkTweet thisAlerts:
@MindzaiJul 04.2010 — ... and how does one create a hyperlink in a web document if not with the HTML anchor tag?
Copy linkTweet thisAlerts:
@narutodude000authorJul 04.2010 — I will be using anchors
[CODE]<a href="...">...</a>[/CODE]
Copy linkTweet thisAlerts:
@narutodude000authorJul 05.2010 — How can I use Regex? I know it's using Regex, but how?
Copy linkTweet thisAlerts:
@criterion9Jul 05.2010 — I know it's using Regex, but how?[/quote]
Why would you bother with a regex based on the previous answer by Mindzai?
Why would you use regex when DomDocument is purpose built for exactly this kind of task? There are just too many variables involved with matching HTML tags.[/QUOTE]
Copy linkTweet thisAlerts:
@YelgnidrocJul 05.2010 — If you want to use RegEx, take a look at:

http://uk3.php.net/manual/en/function.preg-replace.php


Or, for the DomDocument (which is probably the better option):

http://uk.php.net/manual/en/class.domdocument.php
Copy linkTweet thisAlerts:
@sohguanhJul 06.2010 — If you want to use RegEx, take a look at:

http://uk3.php.net/manual/en/function.preg-replace.php


Or, for the DomDocument (which is probably the better option):

http://uk.php.net/manual/en/class.domdocument.php[/QUOTE]


I agree. Depending on the problem, we should choose the best fit. In this case I also prefer DomDocument since it is a HTML document.

Regex can be used in say a non-HTML document, unstructured text (aka free-text) document etc scenarios.
×

Success!

Help @narutodude000 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.4,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...