SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    replace all but four?

    I have a series of dots "1 2 3 .......... 10 11 12"

    I was doing this to make all those dots to be only 4
    PHP Code:
    $nav["page"] = "1 2 3 .......... 10 11 12";

    if(
    preg_match("/(\.+?)/U",$nav["page"], $match)){
        if(
    strlen($match[1]) > 4){
           
    $nav["page"] = preg_replace("/(\.+?)/U","...."$nav["page"]);
        }

    but for some reason it is not working. how do I make it so there is only 4 dots. i should know this but I am working on over time and my brain is drained. in the end all I want is 4 dots, no more. so it doesn't matter how many dots it starts with the total can only be for

    thanks for you help
    success is not by chance, it is by choice.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $nav['page'] = preg_replace('/(\.+?)/U','....', $nav['page']); should work ok. What is making you think it isn't working? Maybe it's some combination i didn't try, but it seems to work ok for me.

  3. #3
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it adds more than 4 dots as why it isn't working. and it is not in any loop.
    success is not by chance, it is by choice.

  4. #4
    SitePoint Zealot devscripts's Avatar
    Join Date
    Sep 2004
    Location
    ur monitor
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php
    $nav["page"] = "1 2 3 .......... 10 11 12";
    $nav["page"] = preg_replace("/(\.){5,20}/","....", $nav["page"]);
    echo $nav["page"];
    ?>

    try that.
    "None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)

  5. #5
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it cuts it down some but still way over 50 dots. but it is lower than the first time I tried
    success is not by chance, it is by choice.

  6. #6
    SitePoint Zealot devscripts's Avatar
    Join Date
    Sep 2004
    Location
    ur monitor
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change the numbers {5,20} to {5,100} and let me know 100 being the highest possible dots to match.
    "None of you [truly] believes until he wishes for his brother what he wishes for himself." By The one and Only Prophet Mohammed (Peace and blessings be upon him)

  7. #7
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't get the original to fail at all.
    PHP Code:
    $nav['page'] = '1 2 3 .......... 10 11 12';
    $nav['page'] = preg_replace('/(\.+?)/U','....'$nav['page']);
    echo 
    $nav['page']; 
    works fine for me no matter how many original ...'s there are.

  8. #8
    SitePoint Guru
    Join Date
    Feb 2004
    Location
    Oregon
    Posts
    686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well it wasn't for me. it didn't even phase it. I have worked around this issue. it will now only add 4 dots and quit. thanks all.
    success is not by chance, it is by choice.


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
  •