By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,408 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,408 IT Pros & Developers. It's quick & easy.

searching phrase (text) in html file

P: n/a
ash
I want search phrase in html file and mark (like Google when I click on
"cached") it (phrase). Does somebody know any class, that can help me? Maybe
somebody know how could I make this?
thanks
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

ash wrote:
I want search phrase in html file and mark (like Google when I click on "cached") it (phrase). Does somebody know any class, that can help me? Maybe somebody know how could I make this?
thanks


$new_html = str_replace ($phrase, '<span
style="css_statement">'.$phrase.'</span>', $old_html);

could be a way.
i didn't test that, if $phrase contains html tags it might mess up your
markup.

micha

Jul 17 '05 #2

P: n/a
ash
> i didn't test that, if $phrase contains html tags it might mess up your
markup.

Yes. I want avoid html tags.
Jul 17 '05 #3

P: n/a

ash wrote:
i didn't test that, if $phrase contains html tags it might mess up your markup.

Yes. I want avoid html tags.


i'm not sure what you mean but here's an example:

$old_html = '<p>some text and some more text</p>';
$phrase = 'text';

so, using above said function
$new_html = '<p>some <span style="put your style here">text</span> and
some more <span style="put your style here">text</span></p>";

all fine

now: $phrase = '<p>some';

$new_html = <span style="put your style here"><p>some</span> text and
some more text</p>";
clearly messed up html

which means: if your search phrases do not contain html tags, above
solution is fine. if they contain tags it's more complicated. i don't
have a solution for that right now.

micha

Jul 17 '05 #4

P: n/a

ash wrote:
i didn't test that, if $phrase contains html tags it might mess up your markup.

Yes. I want avoid html tags.


i'm not sure what you mean but here's an example:

$old_html = '<p>some text and some more text</p>';
$phrase = 'text';

so, using above said function
$new_html = '<p>some <span style="put your style here">text</span> and
some more <span style="put your style here">text</span></p>";

all fine

now: $phrase = '<p>some';

$new_html = <span style="put your style here"><p>some</span> text and
some more text</p>";
clearly messed up html

which means: if your search phrases do not contain html tags, above
solution is fine. if they contain tags it's more complicated. i don't
have a solution for that right now.

micha

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.