PHP few questions
i have few questions to php:
first of all, i have a website powered by php. i'm using a file header.php, which contains the html header, title etc. also i have file index.php, which contains a basic content of page. i simply use
markupinclude("include/header.php");
to include header.php into index.php
but my problem is that as some people here know, i am from czech republic. we are using in our language some special characters as "é,í…" etc. when i had this characters in index.php, everything was ok. but when i'll try to include that header, these chars in that header are replaced with "?", so i have for example in title replaced this characters with "?" i think i have to change charset, but how? and where? in index.php is everything ok, it doesnt work only in includes. default charset is i think utf-8, czech charset is cp-1250, how can i change it?
second question, how can i use php to read some specific text on the page? i dont need all the page, i need only a specific text on it, and save it to a variable. how can i do this?
thanks in advance for any help.
http://www.w3schools.com/php/default.asp will solve you're problem of displaying 'some' text using variables. As the other problem have you been on www.php.net?
thanks both of you, one problem is solved. as for your question, FireSaleHaxor, yes i've already looked at www.php.net
dancuc wrote: thanks both of you, one problem is solved. as for your question, FireSaleHaxor, yes i've already looked at www.php.net
dancuc, i really like ur avatar. mind if i steal it? :D
(see im nice, im asking first)
:P
solved ;) but i have last question for this thread: i'm using if/else statements, like this example:
if(empty($id) || $id == "main")
{```
but i have it on index. when i load page, index will be loaded. but when the index is loaded, there is no index.php?id=, there is ony index.php, and i am getting error Notice: Undefined index: id in *** index.php on line 1027
how can i solve thisQ?
ok here i am sending shorter source:
include("/include/header.php");
echo"<div id=\"menu\">
<ul id=\"mainMenu\">//short version of menu
<li><a href=\"index.php?id=vysledky_07-08\">some content</a></li>
</ul>
</div>\n";
$id = $_GET['id'];
if(empty($id) || $id == "uvod")
{
echo"<div id=\"content\">//short version of content
<h1 class=\"class1\">some content</h1>
<img class=\"class2\" src=\"images/value.jpg\" alt=\"\" />
<h2 class=\"class3\">some content</h2>
<ul>
<li>some content</li>
<li>some content</li>
</ul>
<div id=\"footer\">
<p>Copyright © 2007 dancuc</p>
</div>
</div>\n";
}
echo"</body>
</html>\n";
?>```
i have included header, menu i have in index.php, then is checked status of "id" and depending on this is showed main content
dancuc wrote:
{
if(empty($id) || $id == "uvod")
{
***```
Well, it looks as if you've broken your code again by trying my **change**. Re-read my previous post suggesting the **change**, and you should see the paramount mistake you **added**.
> **dancuc wrote:**
i've tryed lots of things before i posted here. i've tryed relocating the variables and condition, but nothing worked.
You're not thinking about how your conditional is supposed to be working. Write it down on paper in pseudocode before you toss it into a file.
dancuc wrote: here you have, its in czech so sorry if some characters are unreadable
echo"***\n";
$id = $_GET['id'];
if(empty($id) || $id == "uvod")
{
echo"***\n";
}
echo"***\n";
?>```
Dude..
Seriously, read that IF statement and scratch the back of your head. That will never ever work.
EDIT: Just read through the whole thread again, noticed someone already gave you the answer.
yes, you are right Zephyr, i'm posting a fully commented source:
if(!isset($_GET['id']) || empty($_GET['id'])){ //i've decided to not copy $_GET['id'] into a variable id, and work only with $_GET['id']
$_GET['id'] = 'uvod';
}
echo"***\n"; //some echoed html...
if(empty($_GET['id']) || $_GET['id'] == "uvod") //if the id is empty, or if id equals to "uvod"
{
echo"***\n"; //some text
}
else if($_GET['id'] == "blahblah") //can be used for other conditions
{}
?>```
i hope this will help to the others, which are having problems with this. its not that hard, as it look
anyway, again thanks to all for help
Good job. As a slightly more efficient way to do it, you could do this:
<?php
$id = '';
if (isset($_GET['id']))
{
$id = $_GET['id'];
}
if ($id == "") || ($id == "uvod")
{
//do stuff
}
?>
Basically, you can give $id the default value of ''. Then, if the GET variable is set, it will update $id with the value. Finally, you'll test for an empty string or the actual string you're looking for, then go for it.
Oh, and as mentioned earlier… don't forget to sanitize your GET variables. Also, you don't have to echo all of your HTML like that… just use PHP tags in between the standard HTML on your page.
Edit: I still, and always will, hate smilies. Thanks, Spy. lol
:);):|:(:o:pB):D:@:angry::happy::ninja::xx::radio::whoa::wow::vamp::right::love::matey::evil: - Spy