[php][regular expression] attributes uit html tags slopen

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Bartholomew
  • Registratie: Januari 2000
  • Laatst online: 29-04-2024
Hoi ik heb weer een regular expression probleempje en ik hoop dat iemand me hier mee kan helpen.

ik heb deze html:
code:
1
2
<FONT FACE="Arial" SIZE="12" COLOR="#000000">hello!</FONT>
<FONT FACE="Verdana" SIZE="12" COLOR="#FF0000">oohmy</FONT>


en dat moet worden:
code:
1
2
<FONT SIZE="12">hello!</FONT>
<FONT SIZE="12">oohmy</FONT>


nu heb ik de volgende regular expression search/replace die volgens mij de FACE attribute er uit moet strippen maar hij doet helemaal nix ;-(

code:
1
$result =  preg_replace ( '/FACE="\"([^\"]*)\"/i', "", $str);


is er een regular expressions guru in het huis? ;-)

Acties:
  • 0 Henk 'm!

Verwijderd

Daar hebben ze nou css voor uitgevonden ;)
Maar is het misschien geen idee om gewoon alle html eruit te halen met strip_tags() en de rest qua opmaak over te laten aan css?

[ Voor 11% gewijzigd door Verwijderd op 13-10-2004 11:25 ]


Acties:
  • 0 Henk 'm!

  • ACM
  • Registratie: Januari 2000
  • Niet online

ACM

Software Architect

Werkt hier

Volgens mij wil jij FACE="\"....\" eruit strippen ;)
Waarbij op de puntjes 'alles wat geen \ of " is' staat.

[ Voor 36% gewijzigd door ACM op 13-10-2004 11:26 ]


Acties:
  • 0 Henk 'm!

  • crisp
  • Registratie: Februari 2000
  • Laatst online: 00:44

crisp

Devver

Pixelated

PHP:
1
$result =  preg_replace ( '/ FACE="([^"]*)"/i', '', $str);

should do the trick; dubbele quotes hebben geen speciale betekenis in reguliere expressies en hoef je dus niet te escapen (tenzij de expressie zelf tussen dubbele quotes staat).
In jouw voorbeeld stond er gewoon een " teveel na de =

Wat Nokia zegt klopt trouwens ook; font-tags zijn absoluut overbodig en zijn in de HTML recommendation daarom ook deprecated ;)

Intentionally left blank


Acties:
  • 0 Henk 'm!

  • Bartholomew
  • Registratie: Januari 2000
  • Laatst online: 29-04-2024
super bedank crisp!

ik had inmiddels dit gemaakt:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$str = '
<FONT FACE="Arial" COLOR="#000000" SIZE="12">hello!</FONT>
<FONT COLOR="#FF0000" FACE="Verdana" SIZE="12">oohmy</FONT>
';
    
    
preg_match_all ('/FACE=\"([^\"]*)\"/i', $str, $face_chunks);
preg_match_all ('/COLOR=\"([^\"]*)\"/i', $str, $color_chunks);
    
print_r($face_chunks);
print_r($color_chunks);
    
$result = $str;
foreach($face_chunks[0] as $face_chunk)
{
    $result = str_replace($face_chunk,'',$result);
}
    
foreach($color_chunks[0] as $color_chunk)
{
    $result = str_replace($color_chunk,'',$result);
}


werkt wel maar is nie so huul mooi he ;-)

dit is een stuk strakker :)
code:
1
2
$result =  preg_replace( '/ FACE="([^"]*)"/i', '', $str);
$result =  preg_replace( '/ COLOR="([^"]*)"/i', '', $result);

Acties:
  • 0 Henk 'm!

  • crisp
  • Registratie: Februari 2000
  • Laatst online: 00:44

crisp

Devver

Pixelated

of in 1 regel:
PHP:
1
$result =  preg_replace( '/ (FACE|COLOR)="([^"]*)"/i', '', $str);

;)

Intentionally left blank

Pagina: 1