Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Encoding/characterset/font Family Confusion


I could use a bit of guidance on the following matter.

I am starting a new project now and must make some decisions regarding
encoding.
Environment: PHP4.3, Postgres7.4.3

I must be able to receive forminformation and store that in a database and
later produce it on screen on the client (just plain HTML).
Nothing special. I do this for many years, but I never paid a lot of
attention to special characters.

A few day ago I discovered that the euro-sign is not defined in all
fontfamilies.
They cannot produce the right sign no matter if I use € or the
hexadecimal equivalent.
After a little research I found I could put font-tags around the euro-sign
with another font-family (Arial in this case) to get the Euro sign.

I am completely graphical impaired, and only understand programmingcode (and
HTML/JavaScript of course) , so this is a weak point on my side, hence this
question.

I target on Europe only at the moment (no need for Chineese
charactersupport)
That said, will the following setup make sense?

Postgresql db encoding scheme: LATIN1
In the headers of all my HTML: content-type: text/html charset: iso-8859-1

A few related questions:
1) Will people be able to copy/paste info from other sources (like
wordprocessing programs and other websites) into my forms?

2) Can I use regular expressions as I am used to (ASCII) in my PHP code?
Will I match e acute, eurosign, etc?

3) Will the roundtrip describe here under have problems with normal expected
european characters?

client copies some text from some source ->
paste in the form ->
receive by PHP ->
insert in Postgresql (or update) ->
retrieve from postgresql ->
display as HTML (with content-type: text/html charset: iso-8859-1)

Is that OK?
Any pitfalls?
Should I maybe use UTF-8?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read True Type Font (ttf) Tags (font Name...)
I try to acces to the font name of my ttf fonts using a php script
with the file name.
I've found a script reading idv tags from mp3 files, but it's too
specific.
Can anyone say me how to read a ttf file in php ?

Family Tree Approach
I've been working on a simple database for my family to keep our family tree organized.  I've written all the pages to handle inputing the data into the database, but am getting stuck on the best approach for pulling it all out into a family tree.  I want to keep things simple, so I only want it to display parents (no siblings).

However, I'd like the code to be flexible, so it will go as many generations as the database has data for.  I've looked around at a couple of other posts and came across one for a dog pedigree that is essentially the same thing, though it was limited in it's generations.  I've done a bit of research and came across this http://en.wikipedia.org/wiki/Ahnentafel  but I'm not sure if this would actually help me at all.

Right now, my mySql table is set up with an ID field, and then fields for the ID's of that entry's mother and father, along with other relevant data.  I'm basically just not sure on what the best way is to cycle through the database and pull everything out.  I'll worry about the formating later, but right now I'd like to just achieve something like this example http://en.wikipedia.org/wiki/Ahnentafel#Example.

[GD] Could Not Find/open Font - Font Problem
I know this subject was up several times but Icant get it work
use gd2 on win32
<?
putenv('GDFONTPATH=f:swdfont');
$font = "f:/swd/font/arial.ttf";
$im = imagecreate (250, 28);
$black = ImageColorAllocate ($im, 0, 0, 0);
$yellow = ImageColorAllocate ($im, 235, 235, 51);
ImageTTFText ($im, 20, 0, 10, 20, $yellow, $font,
"comming text or not?");
ImagePNG($im,test.png);
?>
<img src="test.png" alt="image">

but I allway get error about not finding font ..

Find Out Encoding Of A File With Php, And Convert It To UTF-8 Encoding
In my script I need to find out the encoding of a file and in case it
is not of the kind UTF-8 I need to convert it to that format.

SID Confusion
I was just looking into the aspects of session handling in PHP (version 4.3
on SUSE-9.1) and I've got confused about the SID constant. The info says
'Constant containing either the session name and session ID in the form of
"name=ID" or empty string if session ID was set in an appropriate session
cookie.'

In practise it appears that SID is set after the initial call to
start_session() which initiates the session, but is empty thereafter. All
subsequent page requests (where the session ID is supplied from the browser
via a cookie) leave the SID empty. Which kind of makes the documentation
make sense, but it leaves me wondering a) why SID is set at the outset, but
is otherwise left empty; and b) is SID of any real use if it's going to be
empty virtually all the time? Do PHP scripts in general make regular use of
the SID constant, and if so, how is it being empty most of the time a
helpful design?

Session Confusion
I have a particular problem that may need an extra brain or two..I am leading users through a 5 step process in a web site. In each step the user will enter info/answer questions and all of the information will be dumped to mysql at the end of the road. I am having a terrible time keeping the information from page to page. I have used sessions before for this and all worked fine but now something is wrong. As a test I am just using three pages (p1.php,p2.php and p3.php) Here is a description of each:

p1.php - session begins and three vars are registered. The three vars are username,password and pin. The page contains a simple form with three text elements: username, password and pin and a submit button. The form is sending the info to p2.php

p2.php - session begins and three vars are registered. The three vars are username,password and pin.
When the session is present the information in the vars will not print out on the page, when I remove the session the info is accesible. I think this has something to do with the information coming from the form? any ideas...

p3.php - session begins and three vars are registered. The three vars are username,password and pin. I want to use the info from page p1.php here but cannot due to the problems on p2.php

Any ideas are greatly appreciated. Here is what I am using for the sessions on each page:

<?
session_start();
session_register("username");
session_register("password");
session_register("pin");
?>

Checkbox Confusion!!!!
I have page1.php that displays some articles from a database by the condition 'on'

What I want to do is have checkboxes so that the articles you check won't be displayed on the web page the next time it's brought up. Essentially turn the articles checked to the 'off' condition and leave the articles that are not checked to the 'on' condition.

When you hit the submit button I want it to go to a page2.php to run an update query to change the 'on' condition to the 'off' condition for the specific articles that were previously checked. (My Primary Key in the database is Article_Number)

I think i have page1.php correct (don't quote me on this!)

<input type='checkbox' name='Display_Article' value='off'>";

But I'm completely lost on what to do for the page2.php

if($submit) {

for ($i=0; $i<count($Display_Article); $i++) {
//echo "<li>".$Display_Article[$i]."</li>";

$sql="Update articles set Display_Article='$Display_Article[$i]' where Article_Number='$Article_Number'";
$result=mysql_query($sql) or die ("Update Query Failed");
}

Timezone Confusion
I'm using PHP4 and have got myself confused over timezones.

I've put a datetime into my MySQL table as a GMT time. MySQL shows me
the data as &#55614;&#57159;-04-06 16:04:56'. I put that in there just after 5pm,
and as I'm in London (GMT+0), but we're now on British Summer Time
(GMT+1), that appears to be correct.

I want to get that datetime out again, and print it into my webpage,
keeping it as GMT. i.e. I want PHP to treat that time as &#55614;&#57159;-04-06
16:04:56'. If I say:

$date = date( 'r', $timestamp );

then it says:

Fri, 06 Apr 2007 16:04:56 +0100

The time is right, but it's reporting my local timezone. If I say:

$date = gmdate( 'r', $timestamp );

then it says:

Fri, 06 Apr 2007 15:04:56 +0000

Now it's got the timezone as I want it (+0000, which is GMT) but the
time is wrong.

It seems that PHP's gmdate() treats the input timestamp value as being
local time, and therefore corrects it by either marking it with the
local timezone (as per the date() function), or 'correcting' it to GMT
(as per the gmdate() function).

Either way, given that I'm starting with an absolute, GMT based time
stamp, this isn't helpful!

I *think* I've got the right timestamp in my MySQL table, and *think*
I'm interpreting the datetime incorrectly in PHP. Can someone explain
where I'm going wrong and how I get PHP to just convert my GMT date/time
number to a GMT date/time string?

Php Xml Mozilla Confusion
I created two different files with almost the exact same content.
file.xml contains pure xml data
file.php contains the exact same data except the first line, this on is
changed to

<?
echo ("<?xml version="1.0" encoding="utf-8"?>");
?>

instead of just

<?xml version="1.0" encoding="utf-8"?>

If I request the xml file in Mozilla or IE it displays the xml content
like those browsers normally do (a nice colorfull tree structure) but if
I request the php file only IE displays it the exact same way as the xml
file (nice and colrfull again), Moz outputs one straight line of text.

Is this a php problem where IE interprets it wrong again and desides to
display it the xml way or is this a browser problem where Moz interprets
it wrong (because it might only display it as nice and colorfull if it
has the xml extension)?

Parse Error Confusion
I wrote this little script and it worked great, but I'm working on redesigning the site and am getting parse errors now that the script is plugged into the new design. Would anyone out there have a pair of fresh eyes to locate the problem?

Aliasing And Reference Confusion....
I hope that someone can set me straight on "alaising" and "references"
in PHP....

I'm a C coder from ways back and this "new fangled" PHP way of doing
things is hurting my brain. :-)

OK, to set the background:

I have an XML document. I am searching it using xpath. So far so good.

Now I need to replace a node value. In PHP4 and libxml 2.4, the
node->set_value method doesn't actually set the value; it appends it to
the node value.

So I've built a function setXpathNodeValue:

function setXpathNodeValue($context, $pattern, $snode,
&$new_content ) {

if ($snode == '') $nodeset = xpath_eval($context, $pattern);
else $nodeset = xpath_eval($context, $pattern, $snode);

$arNodes = $nodeset->nodeset;
$node = $arNodes[0];
if ($node == NULL) return NULL;

$dom = $node->owner_document();

$newnode = $dom->create_element($node->tagname );

$newnode->set_content($new_content );

$atts = $node->attributes();
foreach ($atts as $att ) {
$newnode->set_attribute($att->name, $att->value );
}

$kids = & $node->child_nodes();
foreach ($kids as $kid ) {
if ($kid->node_type() != XML_TEXT_NODE ) {
$newnode->append_child($kid );
}
}

$node->replace_node($newnode );
}

(Yes, this comes almost verbatim from the PHP.net docs.)

Except that I can't figure out how to "pass by reference" the $dom so
that it is actually changed in the original. That's the whole point of
this exercise.

I guess I could just copy over the whole $dom, but that's potentially
enormous....

Mod_rewrite Confusion (localhost)
If i have the following URL:

http://localhost/coolflix/cart/cart...true&movieid=53

how, using mod_rewrite can i get the URL to show:

http://localhost/coolflix/cart/1/53

Regex Or Str_replace Confusion
My mySQL database is a simple inventory-type database with a "price" field
as an integer. The rest of my script relies on price being an integer so I
really don't want to change the data type.

I have a page with an HTML
form where the user can type in new entries into the database. In my HTML
form, I have the "price" field and I want the user to be able to type the
price any way they want. For instance for an item that costs $10,000 they
could type:

10000
10,000
10000.00
10,000.00
etc.

In the php script that the form posts to, I need to have some error
handling so regardless of how the user types the price on the form, it
will get entered into the database as an integer. I'm looking for
something along the lines of this:

if function_bad_characters($price)
{ $price=function_fix_bad_characters($price); }

and with this the user input in "price" is now reformatted so it gets
entered into the database as an integer.

Confusion About Classes And Objects
Using PHP 4.4.4, I have a class defined like so

class CUserItem {
var $m_id;
var $m_children_arr;
function CUserTOCItem($p_id)
{
$this->m_id = $p_id;
$this->m_children_arr = array();
} // CUserItem
function addChild($p_child) {
array_push($this->m_children_arr, $p_child);
} // addChild
function numChildren() {
return count($this->m_children_arr);
} // numChildren
} // CUserItem

then in a separate bit of code, I have an associative array of
objects, with the key being the id and the value being the object.
Unfortunately, when I try and manipulate the objects in the array, it
doesn't take ...

$item = new CUserItem(1);
$item2 = new CUserItem(2);
$toc_items_arr[1] = $item;
$item->addChild($item2);
print $toc_items_arr[1]-

Quote:

Shared Memory Confusion
I'm using the shmop_* functions to create and access shared memory. I've
never used shared memory before, so I apologize if my reasoning is
completely off...

$shm_id = shmop_open(ftok(__FILE__, 'a'), "c", 0600, 32);

That works for the first process, but if I try to launch a second process it
gives me the warning "Unable to create or attach shared memory" and fails.

According to the PHP manual, the 'c' flag will create shared memory, or if
one with the same key already exists, then it will open it for read/write
access - so I'm not sure why doesn't work (should it?). The manual page
mentions the last two args should be zero if I'm opening an existing memory
segment, but I don't know if I'm opening an existing segment when I execute
that line.

According to one of the manual comments, I can determine whether the memory
segment has been allocated already using the 'ac' flag:

1) $shm_id = shmop_open(ftok(__FILE__, 'a'), 'ac', 0, 0);
2) if(!$shm_id){
3) $shm_id = shmop_open(ftok(__FILE__, 'a'), 'c', 0600, 32);
4) }

But what happens if there is a context switch immediately after line 2 has
finished executing? Then two processes could both end up executing line 3,
and I'll get that warning again. Should I just use a semaphore to make
this atomic?

( linux 2.6, php 4.3.8)

Listing Field Names - Confusion
I'm trying to simply list the names of fields within a certain table. On another page I figured out how to list the available tables within a database, using the list_tables & table_name, so I figured I could do the same using the list_fields & field_name - but it doesn't seem to be working.

Code so far: (works with table list/name)

<?

$connect = mysql_connect("localhost","login","pass");

$result = mysql_list_fields($db,"tablename");
$i = 0;
while ($i < mysql_fetch_array($result)) {
$tb_names[$i] = mysql_field_name($result, $i);

echo "$tb_names[$i]<br>";

$i++; } ?>

ASCII Chars Confusion... PHP Thinks One Way (á = 225), MySQL Other (á = 160)
I am having problem in a database I have. The results (contents of the database) have Latin chars (like á, é) and when I try to print them, it shows an space instead of the 'special' char. I tried processing each letter to see its code (ord), and it recognizes correctly (160, ascii extended code for á), but shows an space... But most weird is that echo ord("á"); shows 225, greek letter 'beta' in ascii table!

PS Font
I have been trying to use .pfb fonts (Type 1) to generate dynamic
images. However the text in the images is very aliased and blurred.
This is of course not because of the font or the font style itself.
Please let me know if you have any ideas or opinions about it. Code
snippet:

$SIZE = 14;
$FONT_PATH = "/usr/X11R6/lib/X11/fonts/Type1/hell.pfb";
$FONT = ImagePSLoadFont($FONT_PATH);
$im = ImageCreate(100, 100);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray = ImageColorAllocate($im, 134, 134, 134);

// draw
ImagePSText($im, $str, $FONT, $SIZE, $gray, $gray, 0, $SIZE,0,0,0,16);
ImagePSFreeFont($FONT);

Can You Arc A Font With PHP?
I am writing a program with the GD library and need to arc a font like Photoshop does. I know how to write text, slant a font, etc., but I cannot figure out how to arc it and do other things. Is this possible with PHP?

With Includes / Font Tag
I was wondering how I would be able to strip the <font> tags from a file
when I include it so it can take on the characteristics of my own stylesheet
instead of the font tag attributes.

Font In GD Library?
Is it possible to select a font in the GD library?

PHP Font Boundingbox Help
I'm trying to understand how to work with bounding boxes around text with
the GD2 library. I thought I understood the concepts and wrote a simple
program to make sure. Here it is:

<?php
putenv('GDFONTPATH=c:windowsfonts');
$bbox=imagettfbbox(10,0,"arial.ttf","Hello World");
echo "upper left ($bbox[6],$bbox[7])-----upper right
($bbox[4],$bbox[5])<br><br>";
echo "lower left ($bbox[0],$bbox[1])-----lower right ($bbox[2],$bbox[3])";
?>

The idea is for me to find out the bounding box coordinates for a Hellow
World message. The output produced has me very confused though. It shows
the coordinates as follows:

upper left (-1,-10)-----upper right (66,-10)
lower left (-1,-1)-----lower right (66,-1)

I understand how the lower left coordinate can be -1,-1, and the lower right
coordinate seems logical, too.

How, though, can the upper coordinates have y values of -10? That's below
the baseline! It would seem logical that since I specified a font size of
10 my Y coordinates on the top would be roughly 10 more than the y
coordinates of the lower corners. So, I'd expect the upper coordinates to
be something like (-1,10) and (66,10). Where is the negative 10 coming
from?

Embed A Font
How do I embed a font onto a remote user's machine? Say he dont have a Papyrus but I want him to view the webpage using the Papyrus font.

How To Change Font In GD?
How can I change the font in GD?

Add A New Font To Editor
I want to add a new font to the editor(Innovaeditor).. I changed the font name in editor side and add that font in my fonts folder in control panel...
But the name of the font is like this "??"

ImageString: How Do I Use A Font That Is Not One Of The Default 5?
I am playing with imagegd for generating images, and was wondering if there is a way I could use a font that is not one of the default 5? I remember reading somewhere about a TT font library for imagegd, but don't remember the specifics. If someone could point me in the right direction I would appreciate it.

Making PDFs With PHP - How Do I Add Another Font?
Does anyone have experience adding new fonts to FPDF? The package comes with helvetica, times and courier; I'd like to make PDFs that use Copperplate Gothic.

GD & Text / Font Tricks Anyone?
Does anyone know any tricks->(Read: code) for creating different font effects using the GD Lib. I know how to create images using ttf fonts but they all pretty plain and boring. Shading Effects, Glows, Shadows etc?

Fixed Font Size
I making a web site where people can change the font size with a form on
a seperate page. I store the value in session-variables and read them
every time a page is loaded.

I wonder if it is possible to prevent people changing the fontsize with
Mozilla or IE menu's? Can anyone tell me more about this?

Change Font Size
I need a little help in changing the output of a script with the font size, I am using a users online script, but the output of the font is not specified so it comes out as the browser default size. this is the echo statement

// Show all users online
if ($user==1) {echo $user.' user online'} else {echo $user.' users online'}
?>

Is there a way to add something to this to output a differant font size, I am clueless with php, Not even sure if this is the bit of the script that will change this.

Font Path For Images Using A Mac OSX
all can anyone tell me the fontpath for the mac osx, i dont mind for
which font say Arial. It is compulsory for the function: imagefttext.

Change Font GD Extension
I found a tutorial on how to write text onto an existing image, but now I am having trouble changing the font of the outputted text. Code:

Windows -> UNIX Font
i programmed a security image thing, but i programmed it on my computer, so it's taking it's fonts from C:WINDOWSfonts

the webserver i am trying to implement it on is UNIX..can anyone help on what to set the font path at to load a font? and what's a good font to use? i want to use a serif font since the terminal ones are easier to read via bots.

Font Size In Imagestring()
How do you change the font size when using imagestring() ??

I know you can choose between 1 and 5 but since I added in a font, I do not know how to specify the font size

Here is my code:

imagestring($captcha, 5, 20, 10, $string, $colour);

but as soon as i replace the 5 with my $font, it becomes tiny

Fpdf Adding Font Problm
Have anyone experience problem when trying to add font on fpdf (window version) for type1 font?

Change Font Style In PDF-files
I'm trying to change the font style for Tahoma from normal to italic.
I inserted Tahoma and TahomaBD.
But I can't find anything about changing the style, but underline...

Image With Functions And Font Face.
does anybody know how to change font-face in Arial,Verdana etc. when i'm
using image-functions of PHP?

Font-Size is clear to me...
$fontSize=2
imagestring($im, $fontSize, $px, 34+($i*1.2), $line, $orange);

Thoughts On Font-size Control
I have been researching some different techniques to controll font size
on a webpage and offer users a way to easily manipulate the font and
was curious as to what methods others were using/had used in the past
for this sort of thing.

I have been using static point font sizes on a stylesheet. With a
script that swaps out the stylesheet for one with larger point sizes
upon clicking a button. I chose this technique out of all the others I
have seen because it seemed to offer the most compatability with
slightly out of date browers etc. However the built in font controll
from IE, Firefox etc. still wreaks havoc on my sites layout.

I am worried about using em's as I just dont see how to make that work
in conjunction with images that are far less plyable than the text and
other design elements.

is there any way to supress the view>textsize? Has anyone had
success with em's? Or does anyone have an interesting way to tackle
this problem?

To Install A New Font While View Page!!!!
I am working with chinese fonts and experienced the difficulty as a user to view that page in chinese... How can i add (or install )chinese fonts to the user's system while the user try to view that page!!!!

How To Load Font At Client Side?
How to load font at client side..likeIf I am searching keywords "Hindi" in google search engine..So in the result page I can see the fonts are in hindi, even though hindi font is not installed @ my(client) side..

I dont want to install manually @ client side.. It would be directly handeled via server.. (like above example)so how its possible in php?

Adding Font Effects To A Very Small Php Bit
So I have this small PHP bit and I want a red and bold font on the line that says "This post has been deleted by:" but not sure how to get it in there.  Here's the bit:

$post = 'This post has been deleted by:'. $usr;
$ta = array ('post' => $post,);
$db_string = $this->ipsclass->DB->compile_db_update_string( $ta );
$this->ipsclass->DB->simple_exec_query( array( 'update' => 'posts', 'set' => $db_string, 'where' => 'pid'.$pid ) );

Dynamic CSS - Changing Font Size
I've written a bit of script that allows a user to change the font size on a web page.  I am aware that this can be done via browser settings, but the client wants the feature on the web page.

My script uses a cookie to keep the users font choice persistent.  However, when I run the script, the web page doesn't recognize the users font choice unless I refresh the page.  Once I refresh the page, everything works fine.

So I'm confused as to why the browser doesn't recognize the font choice right away. Any suggestions? Code:

URL Encoding
In one of my PHP applications, I generate a dynamic link to another page. The parameter list contains a few variables with some special characters, so as expected, I use urlencode() to encode the parameters before plopping them into the URL.

For some strange reason, the link doesn't work - I get a "page cannot be displayed" error in IE 6. NS 6 starts to load it, then just stops. Oddly enough, if I go into the location bar (under IE at least), and delete one (1) character, any character from this one particular parameter (search_expr), the page loads fine (albeit with a messed up parameter). Code:

URL Encoding
Can anyone point me in the direction of a tutorial on URL encoding? I am creating a website and i want to use 1 page which contains the layout, then seperate pages with the content. i would do it something similar to this:

http://website.com/index.php?page=links

Then that would just call up a .inc page specified in the page= variable and display it on index.php.

Php Encoding
i was wondering, which is a good-freeware php enconding alternative?
Im running the apache server on a windows platform.

Encoding
I have a problem. How can I transform this xml:
$xml="<name>Niccol&#xF2;</name>"
to this
$xml="<name>Niccolò</name>"

I recive by CURL from a site this xml:

<?xml version="1.0">
<name>Niccol&#xF2;</name>

but, for some reasons, I want:

<?xml version="1.0">
<name>Niccolò</name>


Which Encoding?
Not really a PHP question, but i've got an app that sends me this type of
encoding:

á (&aacute;) translates to %C3%A1
ñ (&ntilde;) translates to %C3%B1

i've tried several decodings with PHP without any good result.
Anyone knows which type of encoding is this and which function to use in
order to decode it with PHP?

Encoding
my website is parsing 4 external xml files (rss feeds) and writes them in a mysql database. my problem is that 2 of the xml files are encoded in utf-8 and 2 of them are windows 1250. when i need to retrieve the data from the database and display it on my site (which is utf-8) i have a problem with special characters that are encoded in windows 1250. I need all the data in my database to be encoded in one way. how to do that ? or is there another way?

Imagettftext Error Cannot Open/Find Font
I uploaded the font to a folder I created called fonts, but it doesn't seem to wanna open. I tried CHMOD the file to 777 the folder to 777. I also tried leaving off the .ttf like someone in the manual suggests. No luck. Do .ttf files need to be uploaded in some special manner? (like a perl file).

I basically copied the text from the php site and changed the file path to reflect my arrangement: PHP Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved