0

When I try this, it will show some spaces or new lines in output, i want to parse or empty spaces and new lines in output:

<?php
$inner_width = "<script>document.write(innerWidth);</script>";
if($inner_width < 800){
   $hashtag = '#focus'; 
}else{
   $hashtag = ''; 
}
?>
<a href='mywebsite/items.php?cat=2<?php $hashtag; ?>'>Item 2</a>

enter image description here

Aso
  • 379
  • 3
  • 13
  • 2
    Are you sure that php file has not spaces, or lines before ``? You can remove `?>` tag at end – SilvioQ Apr 03 '19 at 20:48
  • 2
    Please reformulate, doesn't make much sense. – Jeto Apr 03 '19 at 20:58
  • I added an picture – Aso Apr 03 '19 at 21:02
  • Why you don't use `document.getElementById('IdYourTag').innerHTML = 'Your Content...'` and print inside a tag?. it's a little weird use `document.write()` because **If it is used after an HTML document is fully loaded, it will delete all existing HTML** [Check](https://www.w3schools.com/jsref/met_doc_write.asp). – LuisEduardox Apr 03 '19 at 21:26
  • 2
    The spaces are almost certainly not being generated by `document.write()` but are a consequence of how your PHP file is formatted. – Jason Apr 03 '19 at 21:36
  • i want to use (if) statement, ex: if($inner_width > 800){echo 'g';}else{echo 'l';} – Aso Apr 03 '19 at 21:37
  • 2
    `trim()` function? Also, maybe an XY problem. What are you trying to accomplish here? – waterloomatt Apr 03 '19 at 23:18
  • if($inner_width > 800){ //something }else{//something} thank you. trim() not work for both js and php in my code – Aso Apr 03 '19 at 23:39
  • I still don't understand why you're mixing JS and PHP. The only thing the PHP is doing is echoing out a ` – waterloomatt Apr 04 '19 at 01:01
  • @waterloomatt please see my update answer. i hope you understand me, thanks – Aso Apr 04 '19 at 05:42
  • What does this `$inner_width < 800` -> `"" < 800` even mean? – akinuri Apr 04 '19 at 05:46
  • 800 mean: 800 Screen Pixel. – Aso Apr 04 '19 at 05:53
  • @Aso You are comparing a string (`$inner_width = ""`) to a number (`800`). This won't work. Also your code is short/incomplete. Your problem is not reproducible. I don't understand why people are upvoting/faving this question... – akinuri Apr 04 '19 at 06:02
  • @akinuri you know, my question is about my experience, so if you want to help me, you can write some idea for me. I didn't understand what I'm doing – Aso Apr 04 '19 at 10:13
  • Looks like you're trying to make conditional links based on the screen size. Why? What are you trying to do? Are you trying to determine who is using a phone? Give us _more details about your overall goal_. – waterloomatt Apr 04 '19 at 12:28
  • @waterloomatt My script doesn't work, I want to fix it. – Aso Apr 04 '19 at 13:27
  • @Aso - As it stands, your question doesn't make much sense. I've asked you repeatedly for more details. If you don't know what you want, how can we? So again, ignoring the coding language, what are trying to do? – waterloomatt Apr 04 '19 at 15:43

0 Answers0