Jump to content


Photo

PHP regular expressions


  • Please log in to reply
7 replies to this topic

#1 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 31 August 2006 - 03:46 PM

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  :)

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 31 August 2006 - 03:54 PM

when you say dir what do you mean as folder.name?
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 31 August 2006 - 04:01 PM

i'm sorry, i meant var (variable)

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 31 August 2006 - 04:04 PM

<?php

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

?>


#5 feri_soft

feri_soft
  • Members
  • PipPipPip
  • Advanced Member
  • 147 posts

Posted 31 August 2006 - 04:10 PM

or just

$var = strip_tags($var);

#6 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 31 August 2006 - 04:25 PM

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.

#7 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 August 2006 - 04:27 PM

Strip tags will strip all html tags from a string you pass to the strip_tags function.

Read up on strip_tags over at php.net. You dont need a regular expression.

#8 birdie

birdie
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts
  • LocationBirmingham UK

Posted 31 August 2006 - 04:30 PM

oh wow thanks. I should have looked into that more. Sorry.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users