way2project
way2project

Reputation: 99

how to remove links from a html content using php

I have the following html content:

<p>My name is <a href="way2project">way2project</a></p>

Now I want this text as <p>My name is way2project</p>

Is there any way to do this? Please help me thanks

I used preg_replace but in vain.

Thanks again

Upvotes: 3

Views: 5324

Answers (4)

manuskc
manuskc

Reputation: 794

Checkout Simple Html Dom Parser

$html = str_get_html('<html><body>Hello!<a href="http://stackoverflow.com">SO</a></body></html>');
echo $html->find('a',0)->innertext; //prints "SO"

Upvotes: 1

MultiDev
MultiDev

Reputation: 10649

This seems strange, but not knowing the complete scope of your issue and seeing that you want to do this in PHP, you can try:

$origstring = '<p>My name is <a href="way2project">way2project</a></p>';
$newstring = str_replace('<a href="way2project">way2project</a>', 'way2project', $origstring);

echo $newstring;

Upvotes: 1

Piotr Olaszewski
Piotr Olaszewski

Reputation: 6204

strip_tags you can use this, to remove html tags.

Upvotes: 0

Ibu
Ibu

Reputation: 43810

You can use the strip tags function

$string = '<p>My name is <a href="way2project">way2project</a></p>';

echo strip_tags($string,'<p>');

note the second parameter is the list of allowed tags you wont to ignore.

Upvotes: 2

Related Questions