Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8509557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:28:00+00:00 2026-06-11T03:28:00+00:00

Please read the code below and comments to see what I’m trying to do.

  • 0

Please read the code below and comments to see what I’m trying to do. Its hard to explain in a paragraph.

$url_fixx = 'home/sublink/group-view/product/catview1'; 
// What my variable holds. MY GOAL IS: I want to omit group-view, product and catview1 from this so I use the trick below. 

catview has a random number at the end so I use the code below to find the number at the end and it outputs “catview1” in this case

$string = $url_fixx;
$matches = array();
if (preg_match('#(catview\d+)$#', $string, $matches)) {
    $catViewCatch = ($matches[1]);
 }
// I got this from http://stackoverflow.com/a/1450969/1567428

$url_fixx = str_replace( array( 'group-view/', 'product', 'catview1' ), '', $url_fixx );
// this outputs what I want. 

MY QUESTION IS :

//When I replace "catview1" with $catViewCatch, the whole str_replace doesnt work. 
$url_fixx = str_replace( array( 'group-view/', 'product', $catViewCatch), '', $url_fixx );

Why is that? and what am I doing wrong?

PS: Also my url sometimes changes to something like this.
$url_fixx = ‘home/sublink/group-view/anotuer-sublink/123-article’

How can I tackle all these ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:28:01+00:00Added an answer on June 11, 2026 at 3:28 am

    Both of your examples output the exact same thing. The below code demonstrates this:

    <?php
    $url_fixx = 'home/sublink/group-view/product/catview1';
    
    $string = $url_fixx;
    $matches = array();
    if (preg_match('#(catview\d+)$#', $string, $matches)) {
        $catViewCatch = ($matches[1]);
    }
    echo str_replace( array( 'group-view/', 'product', 'catview1' ), '', $url_fixx );
    echo '<br />';
    echo str_replace( array( 'group-view/', 'product', $catViewCatch), '', $url_fixx );
    ?>
    

    Also, you might consider using preg_replace instead as it will accomplish the task with less code:

    echo preg_replace('#group-view/product/catview[0-9]+#','',$url_fixx);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Noob question here. Please see code below. Where can I read more on this?
Can someone please explain how to read the below code to find last column
Please see my code below. ifstream myLibFile (libs//%s , line); // Compile failed here
Please see the form HTML code below <form method=post action=register> <div class=email> Email <input
--- Edited below with some more testing, please read :) --- I'm struggling trying
Please read the code below: <?php $flag = 1; $name = $_GET['name']; if($name ==
consider you have a code like this, please read the comments as I thought
Please see code below: s = new Socket(nextHopIP, 3434); fileIn = new FileInputStream(fileName); fileOut
I am curious to know why this is happening. Please read the code example
Here is what I got so far. Please read the comment in the code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.