Jump to content

Archived

This topic is now archived and is closed to further replies.

birdie

PHP regular expressions

Recommended Posts

hi, i need desperate help because i have never done anything like this in php.

My aim is to get rid of html tags from a var.

$var = "<div align=center>hell</div>";

i found out that you could use regular expressions but dont know how to use them.

I found <([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1> which should work (probably).

How do i use it exactly in preg_replace or anything else?

Thanks  :)

Share this post


Link to post
Share on other sites
[code]<?php

$var = strip_tags('<div align="center">hell</div>');

?>[/code]

Share this post


Link to post
Share on other sites
oh i'm sorry if you miss understood this. I meant any html tags. Div was just an example

$var could be..
<table>
<div>
<br>
etc etc.

Share this post


Link to post
Share on other sites
Strip tags will strip [b]all[/b] html tags from a string you pass to the strip_tags function.

Read up on [url=http://php.net/strip-tags]strip_tags[/url] over at php.net. You dont need a regular expression.

Share this post


Link to post
Share on other sites
oh wow thanks. I should have looked into that more. Sorry.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.