Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Find a string in HTML and replace it with link #24

Open
ahoiroman opened this issue Jul 6, 2017 · 1 comment
Open

Find a string in HTML and replace it with link #24

ahoiroman opened this issue Jul 6, 2017 · 1 comment

Comments

@ahoiroman
Copy link

Hello,

I would like to use your class to search a html-code for specific human-readable strings (that are shown in the browser - no hidden HTML-stuff) and replace them with a link.

E.G.

  • Search for all strings like "test"
  • Replace all of them with <a href="test.html" title="test">test</a>

I did that by using the simple HTML DOM parser and it has a massive overhead. Is it possible to use your class to solve this in an elegant way?

@glensc
Copy link
Contributor

glensc commented Mar 10, 2021

@ahoiroman perhaps share your current code, will give some ideas to others.

I would say (not tested) to do something like:

// find appropriate node, perhaps;
$tags = $crawler->filter('div');

// walk over the nodes
$tags->each(function (HtmlPageCrawler $node): void {
	$html = '<a href="test.html" title="test">test</a>';
    $node->replaceWith($html);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants