473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Preg Replace

I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.
Jun 2 '08 #1
11 1961
On 4ÔÂ13ÈÕ, ÉÏÎç2ʱ36·Ö, Bruno Rafael Moreira de Barros
<brunormbar...@gmail.comwrote:
I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.
What you want to do is just removing HTML tags?
Jun 2 '08 #2
Bruno Rafael Moreira de Barros wrote:
I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.
$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);
Jun 2 '08 #3
Alexey Kulentsov <ak**@inbox.ruwrote:
>Bruno Rafael Moreira de Barros wrote:
>I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.

$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);
<html>
<head>
<head<meta name="description" content="This has a <brtag">

Whoops...
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 2 '08 #4
Tim Roberts wrote:
Alexey Kulentsov <ak**@inbox.ruwrote:
>Bruno Rafael Moreira de Barros wrote:
>>I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.
$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);

<html>
<head>
<head<meta name="description" content="This has a <brtag">

Whoops...
Incorrect HTML.
Here must be <meta name="description" content="This has a &lt;br&gt; tag">
Jun 2 '08 #5
On Fri, 18 Apr 2008 10:36:27 +0200, Alexey Kulentsov <ak**@inbox.ruwrote:
Tim Roberts wrote:
>Alexey Kulentsov <ak**@inbox.ruwrote:
>>Bruno Rafael Moreira de Barros wrote:
I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.
$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);
<html>
<head>
<head<meta name="description" content="This has a <brtag">
Whoops...
Incorrect HTML.
Here must be <meta name="description" content="This has a &lt;br&gt;
tag">
Indeed, and how many sites have incorrect HTML? A lot more then fully
valid ones... Which is why I'm going te repeat the mantra: "Use a parser
for HTML manipulation or inspectation, not Regex". DOM comes to mind, very
nice package.
--
Rik Wasmus
Jun 2 '08 #6
Rik Wasmus wrote:
Indeed, and how many sites have incorrect HTML? A lot more then fully
valid ones... Which is why I'm going te repeat the mantra: "Use a parser
for HTML manipulation or inspectation, not Regex". DOM comes to mind,
very nice package.
I think I am in big trouble: sometimes I use Regex-based parser, for
HTML too. :) I know about problem with incorrect attributes and can
write regexp to deal with it. Yes, this is much more easy to load file
into DOM document using loadHTML() then to write complex regexp dealing
with all these incorrect cases.
Jun 2 '08 #7
Alexey Kulentsov:
Tim Roberts wrote:
<meta name="description" content="This has a <brtag">

Incorrect HTML.
No it isn't.

(Yet *another* reason not to reinvent this particular wheel.)

--
Jock
Jun 2 '08 #8
Greetings, Alexey Kulentsov.
In reply to Your message dated Friday, April 18, 2008, 12:36:27,
>>>I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.

I would use str_ireplace, but the contents of the two metas change
with the file.

I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.

Thanks in advance.
$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);

<html>
<head>
<head<meta name="description" content="This has a <brtag">

Whoops...
Incorrect HTML.
Here must be <meta name="description" content="This has a &lt;br&gt; tag">
According to standard, you do not need to escape ">", only "<".
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jun 27 '08 #9
AnrDaemon wrote:
Greetings, Alexey Kulentsov.
In reply to Your message dated Friday, April 18, 2008, 12:36:27,
>>>>I have a file with <html><head><meta something...><meta something
else...>. I need to remove that text.
>
I would use str_ireplace, but the contents of the two metas change
with the file.
>
I know preg_replace allows you to do that, but how? I have tried to
learn regular expressions, but I am having serious problems doing so.
>
Thanks in advance.
$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);
<html>
<head>
<head<meta name="description" content="This has a <brtag">

Whoops...
Incorrect HTML.
Here must be <meta name="description" content="This has a &lt;br&gt; tag">

According to standard, you do not need to escape ">", only "<".

Wrong (again). That's why there is &gt; Otherwise the <meta tag may
end prematurely.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jun 27 '08 #10
Greetings, Jerry Stuckle.
In reply to Your message dated Sunday, June 8, 2008, 21:42:36,
>>>>>I have a file with <html><head><meta something...><meta something
>else...>. I need to remove that text.
>>
>I would use str_ireplace, but the contents of the two metas change
>with the file.
>>
>I know preg_replace allows you to do that, but how? I have tried to
>learn regular expressions, but I am having serious problems doing so.
>>
>Thanks in advance.
$without_meta=preg_replace('/<meta[^>]*>/i','',$with_meta);
<html>
<head>
<head<meta name="description" content="This has a <brtag">

Whoops...
Incorrect HTML.
Here must be <meta name="description" content="This has a &lt;br&gt; tag">

According to standard, you do not need to escape ">", only "<".
Wrong (again). That's why there is &gt; Otherwise the <meta tag may
end prematurely.
Welcome to reality!
http://www.rootdir.org/test.html
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Jun 27 '08 #11
AnrDaemon:
Greetings, Alexey Kulentsov.
Here must be <meta name="description" content="This has a &lt;br&gt; tag">

According to standard, you do not need to escape ">", only "<".
I don't know what "standard" you are talking about, but the HTML
specification allows both "<" and ">" in the content attribute.
Content is defined as CDATA, so pretty much anything goes. If you are
talking about the XHTML specification, then yes, "<" needs to be
escaped but ">" doesn't.

--
Jock
Jun 27 '08 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: sinister | last post by:
The examples in the online manual all seem to use double quotes, e.g. at http://us3.php.net/preg_replace Why? (The behavior is different with single quotes, and presumably simpler to...
2
by: Juggernaut | last post by:
Hi I was trying to write a script to replace some text inside some tags. Lets say I had <tag stuff=stuff><tag stuff=otherstuff><another> I wanted it to find all the <tag and remove them. So...
2
by: toedipper | last post by:
Hello, The following bit of code does a preg match and does something if true (sets $browser to ppcie) Without using if then and else's how do I code it so it does not equal what it is...
4
by: system7designs | last post by:
I don't know preg's that well, can anyone tell me how to write a regular expression that will select everything BUT files/folders that begin with ._ or __?(that's period-underscore and underscore...
14
by: frizzle | last post by:
Hi group, I have a function which validates a string using preg match. A part looks like if( !preg_match( '/^(+((*)?)?)$/', $string ) || preg_match( '/(--|__)+/' ,$string) ) { i wonder...
1
by: terence.parker | last post by:
I am trying to do a search through some data, more specifically HTML, to extract data from it. So for example I may have: <b>Title:</b<em>This is a title</em> <b>Name:</b<em>Fred</em> I wish...
5
by: monomaniac21 | last post by:
hi all what is the preg for capitals in a word to be replaced by that word preceded by a space? i need to be able to do this in preg: thisWord := this Word AnotherExample := Another Example
3
moishy
by: moishy | last post by:
If I wanted to match for instance, all characters that are not in <TAGS>, I would search for all ">ANYTHING<". But how do I make that "ANYTHING"? What will be the PREG for absolutely ANY...
1
by: maheswaran | last post by:
Want to replace the field D:\\Program Files\\xampp\\htdocs\\sample into D:\Program Files\xampp\htdocs\sample I tryed lot using ereg/preg replace but not suceed.....
2
by: JanDoggen | last post by:
function vldLicense($lic) { echo "called with lic: ". $lic . "<br>"; echo preg_match('', $lic) . "<br>"; if (preg_match('{4}-{4}-{4}-{4}', $lic) == 0) return false; return true; } gives me:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.