Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Vb Code.

  1. #1
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Vb Code.

    I see in forums, im finding the replace [B] etc with <b>.

    Now, i could use things such as:

    PHP Code:
    str_replace '[B]''<b>'$string ); 
    but the i would have to type out all the possiblilties.

    for example:

    PHP Code:

    str_replace 
    '[color=red']
    str_replace '[COLOR=RED']
    str_replace '[CoLoR=Red'
    and so on, how would i easily make this script? Any ideas?

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    I wouldn't think anyone would likely use CoLoR.... seems silly.
    Accounting for caps and lowercase makes some sense (overall, for the whole word), but just using one should be fine. Certainly using both would be fine, I think. I don't think you'd need to account for anything major.

    You could do it by using--
    PHP Code:
    <?php
    $string 
    //define this;
    $srch '[color=red]';
    $rep '<span color="red">';
    $stlow strtolower($string);
    for (
    $pos strpos($srch,$stlow,$pos+5)) {
       
    $s1 substr($string,0,$pos);
       
    $s2 $rep;
       
    $s3 substr($string,$pos+strlen($srch));
       
    $string $s1.$s2.$s3;
       
    $stlow strtolower($string);
       }
    echo 
    $string//now it's done
    ?>
    That's untested, but I think is along the right lines.


    Using regular expressions ("regex") might be very beneficial too if you want to look into something that complex. They basically allow you to search for patterns in the text.
    Last edited by djr33; 05-23-2007 at 10:50 AM.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Hmm...
    How about "colour"? (British spelling)
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    I agree that's prettier, but in terms of programming, everything, even programs written in/for foreign languages use American English as the code, since that is primarily where it is developed, so that everyone uses it for consistancy.
    That's like using Italian (or Greek) instead of Latin to name an animal species.


    Now, seriously, if you needed that as well, I'd say just repeat the above functions.

    Really, you could put the entire thing into a for each loop and use arrays to store pairs of search/replace strings to edit the text of the string. This could include multiple spellings.

    Including a multiple spelling within a single search term would be tough, since you'd need to note position and what it is, then tell the search function when to do which, etc. Just easier to search twice if the spelling actually differs.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    My English teacher would kill me if I wrote "color".

    And, to make this more valid:

    PHP Code:
    <?php
    $string 
    //define this;
    $srch '[color=red]';
    $rep '<span style="color:#FF0000;">';
    $stlow strtolower($string);
    for (
    $pos strpos($srch,$stlow,$pos+5)) {
       
    $s1 substr($string,0,$pos);
       
    $s2 $rep;
       
    $s3 substr($string,$pos+strlen($srch));
       
    $string $s1.$s2.$s3;
       
    $stlow strtolower($string);
       }
    echo 
    $string//now it's done
    ?>
    Last edited by djr33; 05-23-2007 at 10:50 AM. Reason: (fixing code from above post for typo)
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  6. #6
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hey guys, seems good.

    I think i like the idea of using the "strtolower) function.

    This will mean i will only have to do it once, in lower case right?

    i will just have to include
    PHP Code:
    strtolower $string ); 
    before i do anything else.

    Thanks for your help

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    Oh, note-- strtolower, not str2lower. Several functions in PHP use '2' in them, but I forgot this isn't one of them. //Edited in previous posts.

    Using strtolower() will give you a copy of the string with all lowercase letters. This will change EVERYTHING, including the posts.

    This is why I had to do a sort of mirror operation, checking the lowercase version for position, then mapping that onto the real string to get a final result with the correct replacements and correct capitalization. It's complex, but that type of approach will be needed if you must allow for oddly capitalized tags. I say you don't really need them, but can't hurt, I guess.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by djr33 View Post
    Oh, note-- strtolower, not str2lower. Several functions in PHP use '2' in them, but I forgot this isn't one of them. //Edited in previous posts.

    Using strtolower() will give you a copy of the string with all lowercase letters. This will change EVERYTHING, including the posts.

    This is why I had to do a sort of mirror operation, checking the lowercase version for position, then mapping that onto the real string to get a final result with the correct replacements and correct capitalization. It's complex, but that type of approach will be needed if you must allow for oddly capitalized tags. I say you don't really need them, but can't hurt, I guess.
    Its just new people will end up doing stuff like that, im making it more user freindly if you get me

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,162
    Thanks
    263
    Thanked 690 Times in 678 Posts

    Default

    If you're up for dealing with more complex code, that works.
    but even for new people, if it doesn't work, they'll try to figure out what's wrong, then just fix it. Everyone can learn.
    ...or not, in which case you'd want this

    Good luck.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hmm. So you think its best just to use CAPITAL letters for the code? Then when its wrong, the will figure out and edit it.

    Hmm, could be a possibilty. Would be a lot easier to code :P

Bookmarks

Posting Permissions

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