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 8866665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:50:55+00:00 2026-06-14T16:50:55+00:00

I am developing a site using WordPress & phpBB and as you must be

  • 0

I am developing a site using WordPress & phpBB and as you must be aware that the image paths are generated by these CMSs. What I want is………… to hold the output before sending to browser………….. Make changes to image path depending on the device type and finally output the correct images.

Why do I want to replace the paths?

Because my NORMAL image is 180KB, my MEDIUM image is 90KB an my SMALL image is 30KB and like this have about 20 images on each page and imagine the amount of page speed I will reduce by replacing it with a smaller image for small and slow devices. Also images are cropped to highlight only the important portion for smaller devices hence changing the dimensions will not resolve my issue.

I am also not looking for CSS3 Media Queries as I have a specific reason for not using them.

What will work for me?

As my priority is to keep the page load times to minimal, the best solution would be using some Regular-Expression as I am not using any JavaScript Libraries in my Template.

If this cannot be achieved without JavaScript, then I would prefer plain old JavaScript method without using any libraries as this will be the only JavaScript function in my template and it would not make any sense to load an entire library for it.

The following is what I was thing should be the approach. However I dont know how to get it. Kindly help.

Please Note:- I am very new to PHP and also ZERO at Regex and JavaScript. Hence please explain in a bit detail.

<?php ob_start (); ?> /* Start Buffering */


<div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pellentesque vestibulum fringilla. Nullam eget fermentum neque. Quisque ullamcorper fringilla quam, eu elementum nisl ornare vitae.</p>
<img src="images/desktop/pic1.jpg"/>
<img src="images/desktop/pic2.jpg"/>
<img src="images/desktop/pic3.jpg"/>
</div>

<?php ob_get_contents();  /* Get the Buffer */

if ($layout = 'mobile') {

    /* replace <img src="images/desktop/pic1.jpg"/> with <img src="images/mobile/pic1.jpg"/>
    /* replace <img src="images/desktop/pic2.jpg"/> with <img src="images/mobile/pic2.jpg"/>
    /* replace <img src="images/desktop/pic3.jpg"/> with <img src="images/mobile/pic3.jpg"/>
    The Folder-Name 'desktop' should be replaced by 'mobile'
    */

} else if ($layout = 'tablet') {

    /* replace <img src="images/desktop/pic1.jpg"/> with <img src="images/tablet/pic1.jpg"/>
    /* replace <img src="images/desktop/pic2.jpg"/> with <img src="images/tablet/pic2.jpg"/>
    /* replace <img src="images/desktop/pic3.jpg"/> with <img src="images/tablet/pic3.jpg"/>
    The Folder-Name 'desktop' should be replaced by 'tablet'
    */

}

ob_end_flush (); /* Send Output to the browser */
?>

The values of $layout are being calculated by another PHP Function.

Please feel free to suggest a totally different solution also if you feel that would be a better approach.

  • 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-14T16:50:56+00:00Added an answer on June 14, 2026 at 4:50 pm

    You’re wanting to replace the word “desktop” in your paths to “mobile” or “tablet”. You don’t need a regular expression.

    I was going to suggest using str_replace, but then I realized you don’t need even that.

    Try this on for size:

    <?php ob_start (); ?> /* Start Buffering */
    <div>
        <p>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pellentesque vestibulum fringilla. Nullam eget fermentum neque. Quisque ullamcorper fringilla quam, eu elementum nisl ornare vitae.
        </p>
        <img src="images/<?=($layout !== 'desktop' ? $layout : 'desktop')?>/pic1.jpg"/>
        <img src="images/<?=($layout !== 'desktop' ? $layout : 'desktop')?>/pic2.jpg"/>
        <img src="images/<?=($layout !== 'desktop' ? $layout : 'desktop')?>/pic3.jpg"/>
    </div>
    ?>
    

    What’s weird is that if layout is always set (that is, ‘desktop’ normally, or either ‘mobile’ or ‘tablet’), why do you even need to do a replacement of the url? You could just dynamically construct the url like so:

    <img src="images/<?=$layout?>/pic1.jpg"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using SVN while developing a WordPress site. Now I want to upload
I am developing a Wordpress site in Linux using LAMP environment. I want to
I'm currently developing a site using the WordPress Twenty Eleven theme and I would
I'm developing a mobile site using IUI . It's a framework that makes web
I'm developing web site that loads pages dynamically using the .load function. For example:
Hi I am developing a mobile version of my WordPress site using WP Touch
I'm developing sites using Wordpress and I want to use the lates version of
I am developing a site using ASP.NET, SQL 2008 and LINQ. I want to
I am developing a site using php and mysql. I want to know... what's
I am developing a small site using Wordpress.org and would like multiple parents to

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.