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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:30:40+00:00 2026-05-26T17:30:40+00:00

My trouble is to multiply numbers in string that contains various characters. For example,

  • 0

My trouble is to multiply numbers in string that contains various characters.

For example,

Input:

$k     = 2;    
$input = '<div style="padding:10px 15px; font-size:1em ;height:2%;"></div>';

Output:

<div style="padding:20px 30px; font-size:2em ;height:4%;"></div>

Edit

$k can be any whole number (0-9). All numbers from $input string are multiplied by $k.

  • 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-05-26T17:30:41+00:00Added an answer on May 26, 2026 at 5:30 pm

    I’d use preg_replace_callback:

    $input = '<div style="padding:10px 15px; font-size:1em ;height:2%;"></div>';
    $output = preg_replace_callback('/([0-9]+)\s*(px|em|%)/i', function($matches){
       $k = 2;
       return ($matches[1] * $k).$matches[2];
    }, $input);
    

    The above only replace numbers followed by px, em or %.

    You could also provide $k to the lambda function yourself, for more flexibility:

    $k = 2;
    $output = preg_replace_callback('/([0-9]+)\s*(px|em|%)/i', function($matches) use ($k){
       return ($matches[1] * $k).$matches[2];
    }, $input);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to create a program that takes an input file of unsorted numbers
I'm having some trouble returning multiple values in this program that calculates min, max,
I'm new to DOM and I'm having trouble removing multiple images that I loaded
Having trouble with proper regex for RewriteCond RewriteCond %{REQUEST_URI} !^/foo/ Works as expected, that
I'm building a simple interpreter in python and I'm having trouble handling differing numbers
I am traversing an XML file (that contains multiple tables) using XSLT. Part of
(iOS) I have a view that contains multiple textviews under static headings (see image
I'm having trouble with my sqlite database. I'm trying to write an query that
I'm dealing with some legacy code that stores its data in a proprietary string
I'm having trouble creating multiple xml requests using php's curl_multi_exec. The problem is that

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.