Ask Question Forum:
Model Library:2025-02-08:A.I. model is online auto reply
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by duncanb7
at 2024-04-27 01:52:46
Point:500 Replies:14 POST_ID:828489USER_ID:11059
Topic:
Hypertext Markup Language (HTML);;PHP Scripting Language
I am using $file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol=10') in php that
is working fine and I can echo the contents from $file_url,
Since I would like to program the Symbol in Link , so we put it into variable such as $a
$a=10;
$file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol='.$a);
echo $file_url;
But it fail to echo; and me give error message <h1>Bad Request (Invalid Header Name)</h1>
and I try to $file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol='.constant($a));
and it is also failed and warn it constant() is not made;
Why? Please advise
Also I want to know when we will use constant() in php, what is advantage over using variable ?
Duncan
is working fine and I can echo the contents from $file_url,
Since I would like to program the Symbol in Link , so we put it into variable such as $a
$a=10;
$file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol='.$a);
echo $file_url;
But it fail to echo; and me give error message <h1>Bad Request (Invalid Header Name)</h1>
and I try to $file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol='.constant($a));
and it is also failed and warn it constant() is not made;
Why? Please advise
Also I want to know when we will use constant() in php, what is advantage over using variable ?
Duncan
Author: duncanb7 replied at 2024-04-27 10:24:18
Thanks for your reply,
Only
$var="0"
$data = array('Symbol'=>$var);
$url = "http://www.othersite.com/test.aspx?".http_build_query($data);
echo $url;
Only
$var="0"
$data = array('Symbol'=>$var);
$url = "http://www.othersite.com/test.aspx?".http_build_query($data);
echo $url;
Author: duncanb7 replied at 2024-04-27 09:51:22
Be reminded 10 is variable ,
Accepted Solution
Expert: darren-w- replied at 2024-04-27 07:05:53
240 points EXCELLENT
<?php$data = array('Symbol'=>10);$url = "http://www.othersite.com/test.aspx?".http_build_query($data);echo $url;?> 1:2:3:4:5:6:7:
Another way of doing it.
Expert: Lukasz Chmielewski replied at 2024-04-27 06:46:57
Expert: Ray Paseur replied at 2024-04-27 06:43:48
You might use something like this to make your URL string visible.
Instead of this...
$a=10;
$file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol='.$a);
echo $file_url;
Try this...
$a=10;
$url = "http://www.othersite.com/test.aspx?Sybmol=$a";
echo $url;
$file_url =file_get_contents($url);
echo $file_url;
You might also want to check the spelling of Sybmol vs Symbol. You might also want to learn about this function:
http://php.net/manual/en/function.urlencode.php
There is also the possibility that the GET argument keys are case-sensitive, so Symbol would be different from symbol.
Instead of this...
$a=10;
$file_url =file_get_contents("http://www.othersite.com/test.aspx?Sybmol='.$a);
echo $file_url;
Try this...
$a=10;
$url = "http://www.othersite.com/test.aspx?Sybmol=$a";
echo $url;
$file_url =file_get_contents($url);
echo $file_url;
You might also want to check the spelling of Sybmol vs Symbol. You might also want to learn about this function:
http://php.net/manual/en/function.urlencode.php
There is also the possibility that the GET argument keys are case-sensitive, so Symbol would be different from symbol.
Assisted Solution
Expert: Ray Paseur replied at 2024-04-27 06:39:59
80 points EXCELLENT
Buy this book and work through the examples. From this question and some of your others here at EE I can see that you need some foundation in how PHP works - syntax and structure, etc. It will really be helpful to you, I promise!
http://www.sitepoint.com/books/phpmysql4/
http://www.sitepoint.com/books/phpmysql4/
Author: duncanb7 replied at 2024-04-27 02:43:59
I tried this before and it is also fail that is why I put back 'http://www.othersite.com/test.aspx?Sybmol='
int file_get_contents()
int file_get_contents()
Expert: darren-w- replied at 2024-04-27 02:24:05
Could you explain more, What is different form your code to my code about $a
I open and close the speech marks using the same type of paresis
ie :
$a = 10; //define $a to be 10$b='http://www.othersite.com/test.aspx?Sybmol='.$a; //$b = http://www.othersite.com/test.aspx?Sybmol=10$file_url =file_get_contents($b); //gets the content returned into $file_url 1:2:3:
Author: duncanb7 replied at 2024-04-27 02:17:49
Author: duncanb7 replied at 2024-04-27 02:17:22
Is it related to the seting in php.ini file ?
Author: duncanb7 replied at 2024-04-27 02:13:52
Do we need to define varaible.
I get used to for example, if need a variable just typing
$a;
$b= $a+1;
I never use Dim to define variable like in VBA
I get used to for example, if need a variable just typing
$a;
$b= $a+1;
I never use Dim to define variable like in VBA
Author: duncanb7 replied at 2024-04-27 02:12:17
Could you explain more, What is different form your code to my code about $a
Assisted Solution
Expert: hernst42 replied at 2024-04-27 02:11:44
80 points EXCELLENT
constant is a way to use PHP constants dynamicly instead of writing them at parse time. So instead of
if ($condition) $x = A else $x =B;
you could use:
$x = constant($condition ? 'A' : 'B');
Typical you don't use constant at all when programming.
For your error it seems that variable a ist not defined.
if ($condition) $x = A else $x =B;
you could use:
$x = constant($condition ? 'A' : 'B');
Typical you don't use constant at all when programming.
For your error it seems that variable a ist not defined.
Assisted Solution
Expert: darren-w- replied at 2024-04-27 02:01:05
100 points EXCELLENT
your open with a " and closing with a ' amended code above