Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strip out variable values

Status
Not open for further replies.

JamesManke

Programmer
Jul 1, 2004
54
CA
Hi there,

I have a variable with the following value...

[size=18:5aa59a030f]TIPS & TRAPS FOR LANDLORDS[/size:5aa59a030f]

I want to strip out anything in between the [] so that I am left with ...

TIPS & TRAPS FOR LANDLORDS

How would I go about doing this?

Thanks for your help!
 
This script:

Code:
<?php

$a = '[size=18:5aa59a030f]TIPS & TRAPS FOR LANDLORDS[/size:5aa59a030f]';

$a = preg_replace ('/.*\]([^\[]*)\[.*/', '$1', $a);

print $a;

?>

Returns:

TIPS & TRAPS FOR LANDLORDS




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Say the variable read...

[size=18:5aa59a030f]TIPS & TRAPS FOR LANDLORDS[/size:5aa59a030f] then there was more text bla bla bla

If I wanted to remove everything in the [] and have "TIPS & TRAPS FOR LANDLORDS" bolded but the rest of the variable not bolded.

Is it possible to do this?

Thanks for your fast reply on the last one:)
 
Code:
<?php

$a = '[size=18:5aa59a030f]TIPS & TRAPS FOR LANDLORDS[/size:5aa59a030f]';

$a = preg_replace ('/.*\]([^\[]*)\[.*/', '[COLOR=red]<strong>[/color]$1[COLOR=red]</strong>[/color]', $a);

print $a;

?>
 
This script:

Code:
<?php

$a = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec vestibulum porttitor pede. Curabitur varius, est id rhoncus iaculis, augue wisi sagittis mauris, ac molestie tellus.[size=18:5aa59a030f]TIPS & TRAPS FOR LANDLORDS[/size:5aa59a030f]Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed tempor, enim pulvinar interdum convallis, justo urna varius arcu, id luctus lectus justo id magna. Donec.';

$a = preg_replace ('/.*\]([^\[]*)\[.*/', '$1', $a);

print $a;

?>

Returns:

TIPS & TRAPS FOR LANDLORDS


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
If I wanted to remove everything in the [] and have...

Did you mean:
If I wanted to remove everything in the [] including the square brackets?
 
Sorry what I was looking for was....

$a = '[size=18:5aa59a030f]TIPS & TRAPS FOR LANDLORDS[/size:5aa59a030f]Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed tempor, enim pulvinar interdum convallis, justo urna varius arcu, id luctus lectus justo id magna. Donec.';

to return...

<b>TIPS & TRAPS FOR LANDLORDS</b><br />
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed tempor, enim pulvinar interdum convallis, justo urna varius arcu, id luctus lectus justo id magna. Donec.

So between the ][ I need to somehow bold it and place a break at the end.

Thanks for your guys' help, muchly appreciated!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top