Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Replace after <if>

    Ok, I need your help with something.
    I want to have something like this:
    PHP Code:
    $test "<if>Hello world</if>";
    //Now, I want to replace anything after the <if> tag with nothing. But I want it to end and execute the rest of the code once </if> is there
    //How can I do this? 
    Basically that's it.
    I'm not 100% how I would do this.
    Could you help me out what I can do?
    Thanks a lot.

  • #2
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Would you use Regex or something?
    (Sorry, couldn't edit post)

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    IF, ELSEIF, ELSE is setup like this

    PHP Code:
    if ($blue == $color) {
    echo 
    'Yes blue is a color.';
    }
    elseif (
    $blue == $animal) {
    echo 
    'Blue is not an animal';
    }
    else {
    echo 
    'Blue is neither a color or animal';

    Last edited by masterofollies; 01-09-2010 at 04:34 AM.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    Regular Coder
    Join Date
    Dec 2009
    Location
    UK
    Posts
    495
    Thanks
    0
    Thanked 58 Times in 58 Posts
    PHP Code:
    $test "<if>Hello world</if>";
    $test preg_replace('%(<if>).*?(</if>)%i''$1$2'$test); 
    Something like that?
    Not quite sure what you meant to be honest, especially the execution thing
    My site: JayGilford.com
    Resources:
    PHP Pagination Class | Getting all page links | Handling PHP Errors properly
    If you like a users help, show your appreciation with the rep and thanks buttons :)

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    There is no tag called <if>
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    Quote Originally Posted by masterofollies View Post
    IF, ELSEIF, ELSE is setup like this

    PHP Code:
    if ($blue $color) {
    echo 
    'Yes blue is a color.';
    }
    elseif (
    $blue $animal) {
    echo 
    'Blue is not an animal';
    }
    else {
    echo 
    'Blue is neither a color or animal';

    this would always be true,

    you need to have double equals; if($Value == $Something)

  • #7
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    I'm confused with the original post, as masterofollies pointed out if already has a purpose. if is a reserved word in php and it's not a good idea to use it in other ways.

    http://www.php.net/manual/en/reserved.keywords.php

    Perhaps you could explain what <if> </if> is for.


    ---------------
    Leonard Whistler

  • #8
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Of course I know <if> isn't a tag.
    I was going to have <if> in a template for easy use.
    Anyways, I'm not sure I'm going to use it anymore, but thanks anyways guys.

  • #9
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by angst View Post
    this would always be true,

    you need to have double equals; if($Value == $Something)
    Crap haha I don't know where my head is today. Variable signing is single, comparing to is double. Blah!
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #10
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by Crisp View Post
    Of course I know <if> isn't a tag.
    I was going to have <if> in a template for easy use.
    Anyways, I'm not sure I'm going to use it anymore, but thanks anyways guys.
    What your talking about is searching for a unique thing in a file, so you can upgrade the file remotely and it auto install into the script.

    SMF forums does this very thing. You want to install a mod? run it and it updates all the scripts and your done. Am I correct on what you are talking about?
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #11
    New Coder
    Join Date
    Feb 2009
    Posts
    96
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Actually I'm creating my own forum software.
    That's why I have a few threads here asking for a few things.
    Trying to get the best and easiest way to use, and code.

  • #12
    Regular Coder seco's Avatar
    Join Date
    Nov 2008
    Location
    Oregon
    Posts
    687
    Thanks
    6
    Thanked 79 Times in 77 Posts
    i would suggest reading some php.net stuff.

  • #13
    Regular Coder
    Join Date
    Nov 2009
    Location
    Hamilton, New Zealand
    Posts
    126
    Thanks
    0
    Thanked 17 Times in 17 Posts
    When I read this post the other day, I assumed you wanted to search for the contents of the <if> tag, and execute the contents of the tag (using some custom functions/scripts/wrapper), and delete the if tag and contents for echoing to the screen. Or something similar...

    Anyway, I use a similar method for the CMS I'm developing, allowing users the ability to use some custom PHP functions and such.
    Affordable Web Design (New Zealand Based)
    Internet Marketing Guru
    PHP/mySQL Expert
    -------------------------------------------


  •  

    Posting Permissions

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