CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2000
    Posts
    129

    Help with search

    I was wondering if there was an easy way to do this. I need to search a image tags in a bb post. The tags can be [ img] or < img> (since I dont want vB to try and do something with it I put a space).

    Right now I have a loop to find the [ img] start and ending tags. It works great using strpos. But I really dont want to have to do this long loop again to find the start and end < img> tags. So I was wondering if anyone had any idea on how I can do this in one loop. Like with something simular to preg_match or something.

  2. #2
    Join Date
    May 2004
    Location
    Germany
    Posts
    655

    Re: Help with search

    well, what do you want to do with these tags when you found them?

    if want to replace them with something else, you can use preg_replace or (if its a more complex replacement) preg_replace_callback.

    (or the other regexp functions, if don't like the preg_* syntax)

    Code:
    $string = "Hello [ img]you.jpg[/ img] !";
    
    echo preg_replace( '@\[ img\](.*)\[/ img\]@', '<img src="$1"/>', $string );
    this echoes Hello <img src="you.jpg"> !
    Last edited by bigBA; August 18th, 2005 at 02:56 AM.
    there are 10 kinds of people. those who understand binary and those who don't...

    rate a post if you find it usefull, thx
    check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured