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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:24:38+00:00 2026-05-31T19:24:38+00:00

Dear all expert i had a problem for comparing my string from document.write with

  • 0

Dear all expert i had a problem for comparing my string from document.write with a php’s string and when i use var_dump(variable) i see that the string is not the same even though echo value is the same, any know about to make it work?

$resolution_width = "<script type='text/javascript'> document.write(window.screen.width); </script>";

$resolution_height = "<script type='text/javascript'>document.write('#'+window.screen.height+'#'); </script>";  


$screen_width=$resolution_width; 
$screen_height=str_replace("#","",$resolution_height); 

echo var_dump($screen_width);
$str='1280';
echo "<BR>";
echo "<BR>".var_dump($str);

if($screen_width=='1440'){
    $width=1440;
    echo $width;
}
elseif($screen_width=='1360'){
    $width=1360;
    echo $width;

}
elseif($screen_width=='1280'){
    $width=1280;
    echo $width;

}
elseif($screen_width=='1152'){
    $width=1152;
    echo $width;
}
elseif($screen_width=='1024'){
    $width=1024;
    echo $width;
}
elseif($screen_width=='800'){
    $width=800;
    echo $width;
}

This is my result when i try to output it, as it false every comparison.
I think this string is the same but it maybe different conversion.

My result :

string(78) "1280"
string(4) "1280"
  • 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-31T19:24:40+00:00Added an answer on May 31, 2026 at 7:24 pm

    The code inside the <script> tags won’t run until it is in the web browser. The php generates a document to send to the web browser. Then the web browser runs the javascript.

    There is no way to figure out the screen width in the php code. However you can use javascript and css to modify the page layout based on the screen width after the page has loaded.

    If you are trying to format your page, based on the screen width, then I would recommend using Twitter Bootstrap. Handling all the different screen sizes can get hairy. There are a lot of browser compatibility problems and other complications that aren’t obvious at first. The people at Twitter have already solved them and shared this framework so that you don’t have to repeat the work.

    If you don’t want to use the Bootstrap framework, then look at using CSS Media Queries.

    If you need to send the browser width to your server for a different reason, then ajax would be a good way to do that. You will have to have two php scripts. One that generates the page, and one that handles the ajax request. If you are using jQuery then you can write the ajax request like this:

    $( function() {
        $.get( 'script_that_will_proccess_ajax.php', { width: window.screen.width, height: window.screen.height } )
        .success{ function {
            alert( 'it worked' );
         } );
    } );
    

    See the documentation for jQuery get and jQuery post

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

dear all, i'll take some data from the database. and join two tables.the code
Dear experts, I am quite new to javascript and I often see coders use
Dear all, I've been stuck with this problem now for a few days and
dear all.. i'm new to ajax timer, since someone tell me to use it
iphone http://sharingdream.com/phone.jpg Dear all, I'm having a strange problem with an application I'm building
dear all.. i have a DB which built use Mysql. for this case, i
Dear all, I am using java rmi for my program, from client side i
Dear all, I have a data frame which comes directly from a sensor. The
Dear all, i want to show some data in one row from 1 column
Possible Duplicate: LINQ Between Operator Dear All, Hi, I need to write this query

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.