1

I want to put my global variable into echo code in php. My code is below.

<?php
global $result;

code { 
 ...
  }

$result;
//중첩검색&결과내 검색 폼 만들기
echo "<form class=\"category 2\" name=\"search\" action=\"display.php\" onsubmit=\"return validateForm()\" method=\"get\">     
Input: <input type=\"text\" name=\"search\" id=\"qstra\" onkeyup=\"showUsera()\" > 
 // Next line is something wrong!!!!!!!!!!!!!!!!!!!!!!!!!!
<input type=\"text\" name=\""?><?php $result ?><?php "\" id=\"pstra\" onkeyup=\"showUsera()\" > 
***//I want to have name = $result from global.*** 
</form>
<div id=\"hint1\"><b>information will be listed here.</b></div>";

?> 

I am a weak php programmer. Please give me a piece of advice.

3
  • Since you are echoing a string, read about string concatenation. You will have something like: echo 'blablabla' . $result . 'blablabla' Reference: stackoverflow.com/questions/8336858/… . Commented May 2, 2018 at 5:52
  • Yeah. But my echoing code include html tag. and Attribute's value has double quotation, so excaping double quotation and inserting php variable is conflicting. So i want that help/ Commented May 2, 2018 at 5:57
  • 2
    You can use single quotation as your main in PHP and then you won't need to escape the double quotes for attribute values. Commented May 2, 2018 at 5:58

1 Answer 1

1

Use php string concatenation

<input type=\"text\" value=".$result." name=".$result." id=\"pstra\" onkeyup=\"showUsera()\" 
Sign up to request clarification or add additional context in comments.

3 Comments

Yeah. That is almost yes. But, global $result variable don't enter attribute's value in input tag.
@Drohjho check now
Thank you a lot !! That saves me!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.