edwinhermann 57 Junior Poster

The PHP code should not display to the browser. Your query as to why the XHTML validator is failing your code is not really a PHP question but more an HTML question.

I suggest you post the entire HTML code (copy/pasted from the browser View Source). Some people here may be able to help you work out why the XHTML validator doesn't like your code, but a better forum would be the HTML and CSS one here: http://www.daniweb.com/forums/forum143.html

edwinhermann 57 Junior Poster

That code looks good. Verify in your "View Source" (in the browser) that it comes out as:

<span style="font-size: 80%;"></span></li>
edwinhermann 57 Junior Poster

ive tried all ways of putting this part of the code

.'<strong>$session->username</strong> <span style='font-size: 80%;'></span></li>'
."<strong>$session->username</strong> <span style=\"font-size: 80%;\"></span></li>"
.'<strong>$session->username</strong> <span style="font-size: 80%;"></span></li>'

none of these work the middle one actually throws up 5 more validator errors. Am i using the wrong doctype due to the page having php in.

Can you show us the code which includes that line? THe original code you posted does not contain the <span style> code.

edwinhermann 57 Junior Poster

strong>$session->username</strong> <span style='font-size: 80%;'></span></li>'

The bit that's wrong is the use of single quotes instead of double quotes in HTML.

The "span" tags should read:

<span style="font-size: 80%;"></span>
edwinhermann 57 Junior Poster
<?php
function find_value($input) {
// $input is the word being supplied by the user
$handle = @fopen("/users/edwin/list.txt", "r");
if ($handle) {
  while (!feof($handle)) {
    $entry_array = explode(":",fgets($handle));
    if ($entry_array[0] == $input) {
      return $entry_array[1];
      }
    }
  fclose($handle);
  }
return NULL;
}
?>
edwinhermann 57 Junior Poster

I noticed I forgot to answer your question earlier:

So this code grabs what the put in the place of the asterisk? If so, then Thank you very much.

Yes, that is exactly what this code does. Based on the pattern ($p1) and the string ($p2) it works out what the asterisk represents.

edwinhermann 57 Junior Poster

Actually I've just found a way of shortening it even further:

<?php

$p1 = "Hi my name is *";
$p2 = "Hi my name is Edwin";

preg_match(str_replace('*','(.*)','/^'.preg_replace_callback('/([^\*])/miU',create_function('$c','return \'\\x\'.str_pad(dechex(ord($c[1])),2,"0",STR_PAD_LEFT);'),$p1).'$/miU'),$p2,$matches);
$output = $matches[1];

echo $output;	// Edwin

?>

But if you want a more expanded version so that you can work out what each part is doing:

<?php

$p1 = "Hi my name is *";
$p2 = "Hi my name is Edwin";

function get_PCRE_hex_escape_sequence($matches) {
$ascii_decimal = ord($matches[1]);
$ascii_hex = dechex($ascii_decimal);
$ascii_hex_zero_padded = str_pad($ascii_hex,2,"0",STR_PAD_LEFT);
$escape_sequence = '\x'.$ascii_hex_zero_padded;
return $escape_sequence;
}

$escaped_pattern = preg_replace_callback('/([^\*])/miU','get_PCRE_hex_escape_sequence',$p1);
$escaped_regular_expression = '/^'.$escaped_pattern.'$/miU';
$completed_regular_expression = str_replace('*','(.*)',$escaped_regular_expression);

preg_match($completed_regular_expression,$p2,$matches);
$output = $matches[1];

echo $output;	// Edwin

?>
edwinhermann 57 Junior Poster

Ok, here you go:

<?php

$p1 = "Hi my name is *";
$p2 = "Hi my name is Edwin";

preg_match(str_replace('*','(.*)','/^'.preg_replace_callback('/(.)/miU',create_function('$c','return ($c[1] !== \'*\') ? \'\\x\'.str_pad(dechex(ord($c[1])),2,"0",STR_PAD_LEFT) : \'*\';'),$p1).'$/miU'),$p2,$matches);
$output = $matches[1];

echo $output;	// Edwin

?>

I've tested the code and it appears to work as intended. So for example if you had:

$p1 = "I said that * was my name";
$p2 = "I said that Tim was my name";

Then the output is "Tim"

edwinhermann 57 Junior Poster

Is the input the entire sentence, or just the name "Tim"? In the case of the latter, and aside from capitalisation, and assuming it's only the asterisk you ever want to replace, then use this:

$input = "Tim";
$pattern = "Hi my name is *";
$output = str_replace("*",$input,$pattern);

Or is "Tim" the thing you want to output?

edwinhermann 57 Junior Poster

Thank you. I have tried it and it is still only printing the default. The database entry for $perm is Low.

I think it must be to do with $perm not being set properly, because before I posted my solution I tested it first by adding $perm = "Intermediate"; at the beginning.

(By the way, every time I see the variable $perm I think it says "sperm" :-))

edwinhermann 57 Junior Poster
$low = "Low";
$int = "Intermediate"; 
$high = "High "; 

switch($perm) {
     case $low: echo "Low perm <br>"; break;
     case $int: echo "Intermediate perm <br>"; break;
     case $high: echo "High perm <br>"; break;
     default: echo "No information has been provided. ";
}
edwinhermann 57 Junior Poster

Oh yeah, I forgot :) WickedSelf is right.

Alternatively, you can take out the dot-double-quote, so you're left with this:

$result = mysql_query("SELECT COUNT(*) FROM TEST Where Name LIKE 'Smith%'") or die(mysql_error()); 

// Print out result
while($row = mysql_fetch_array($result)){
	echo "There are ". $row[0];
}
edwinhermann 57 Junior Poster
$result = mysql_query("SELECT COUNT(*) FROM TEST Where Name LIKE 'Smith%'") or die(mysql_error()); 

// Print out result
while($row = mysql_fetch_array($result)){
	echo "There are ". $row[0] .";
}
edwinhermann 57 Junior Poster

Use this function:

function rmdir_recursive($dir) {
$files = scandir($dir);
foreach ($files as $file) {
  if (  ($file == ".") || ($file == "..") ) {
    continue;
    }
  $file = $dir . '/' . $file;
  if (is_dir($file)) {
    rmdir_recursive($file);
    rmdir($file);
    }
  else {
    unlink($file);
    }
  }
rmdir($dir);
}

Call it like so:

$dir = "image";
rmdir_recursive($dir);
edwinhermann 57 Junior Poster
$result = substr($string,0,5);
edwinhermann 57 Junior Poster

Actually there are a few "echo" lines. These will prevent any redirects from taking effect. Your logic needs some rethinking, I think.

edwinhermann 57 Junior Poster

You need to put some debugging lines in to see where it's going back to login.php. There are two instances of header("login.php"). I suggest before each one you write some output (which will also prevent the redirect) so that you can identify which path your script is taking.

Also line 21 looks suspicious:

exit;

Seems like if the "else" path is taken in line 13 then it will only get as far as line 21 at which point the script will halt.

edwinhermann 57 Junior Poster

I'm not entirely sure what you mean from your previous post.

If it's any help, the get_included_files() function only reports files that have been included using include(), include_once(), require() or require_once().

If you read a file normally (e.g. file_get_contents(), fopen() or other similar methods) then they will not show in get_included_files().

edwinhermann 57 Junior Poster

get_included_files() returns an array with the files that were included. So, for example, if you were expecting "licence.php" to be included, then you could use this to check:

<?php
if (array_search("licence.php",get_included_files()) === false) {
  // handle error here
  }
?>
edwinhermann 57 Junior Poster

IonCube is quite expensive!

I would use the function get_included_files() to determine what was included. See http://nz2.php.net/manual/en/function.get-included-files.php for more information.

edwinhermann 57 Junior Poster

He must have copy and pasted wrong. It works...

Err - yes sorry copy/paste error :) I only pasted some of the code (it was 2 am when I did this!) As you said, it does indeed work - I just tried it again just to check.

edwinhermann 57 Junior Poster

How about this for a one-liner:

echo preg_replace_callback('/<a ([^>]+)>([^<]*)<\/a>/m',create_function('$matches','return str_replace(" ","_",$matches[0]);'),$string);

BEFORE:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed in ante nec nisl vulputate faucibus at quis <a href="path/to/page" class="pageLink">felis</a>. Aliquam vel dui orci. Integer eget eros sed lorem vestibulum aliquet. Aliquam tortor lorem, semper et rutrum a, hendrerit non tellus. Donec <a href="path/to/page" class="pageLink">sodales nunc</a> sed justo viverra luctus. Proin magna lectus, posuere sed laoreet dapibus, mattis at odio. Fusce sed ultricies augue. Curabitur id eros eu turpis imperdiet vestibulum. Nam <a href="path/to/page" class="pageLink">vitae ante dolor</a>, et placerat elit. Suspendisse nec dictum lectus. Morbi nisi nunc, porta nec tempor non, mollis sed justo. Sed pulvinar commodo consectetur.

AFTER:

<a_href="path/to/page"_class="pageLink">felis</a>. Aliquam vel dui orci. Integer eget eros sed lorem vestibulum aliquet. Aliquam tortor lorem, semper et rutrum a, hendrerit non tellus. Donec <a_href="path/to/page"_class="pageLink">sodales_nunc</a> sed justo viverra luctus. Proin magna lectus, posuere sed laoreet dapibus, mattis at odio. Fusce sed ultricies augue. Curabitur id eros eu turpis imperdiet vestibulum. Nam <a_href="path/to/page"_class="pageLink">vitae_ante_dolor</a>, et placerat elit. Suspendisse nec dictum lectus. Morbi nisi nunc, porta nec tempor non, mollis sed justo. Sed pulvinar commodo consectetur.

colweb commented: Perfect example of a reg expression in action. +3
Venom Rush commented: Brilliant! Thanks for the help ;) +3
edwinhermann 57 Junior Poster

Firstly, I should point out that not all email addresses are of the form something@letters.2-3letters.

For example: john@vuw.ac.nz, bob@blah.travel, fred@sprint.mobi, and so on.

I recommend you use this logic to determine the validity of an email address:

if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,})$/',$email)) {
  echo "Invalid address";
  }

Obviously you'll need to replace the contents of the IF loop to perform what it is you want (e.g. a redirect, displaying an error message, etc).

However - if you want something@letters(WithNoDots).2-3letters then this should do it:

if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z]{2,3})$/',$email)) {
  echo "invalid address"
  }
edwinhermann 57 Junior Poster

is there a way to group all of the OR's together so that the statement is true if any one of the OR statements are true.

You can use brackets to group things together.

For example:

WHERE (a = b OR c = d OR d = e) AND (f = g)

or

WHERE (a = b AND c = d) OR (e = f)

These are just a couple of random examples do illustrate the point. By using brackets, everything inside brackets is evaluated first.

THe first example requires either a to be equal to b, or c to be equal to d, or e to be equal to e, and as well as at least one of those being true, f must equal g.

The second example requires that a is equal to be and b is equal to c, or, if not the case, then e must be equal to f.

edwinhermann 57 Junior Poster

The only way I can think is like this:

$sql = "SELECT * FROM something WHERE id LIKE \"%,".$test.",%\" OR id LIKE \"".$test.",%\" OR id LIKE \"%,".$test."\"";
edwinhermann 57 Junior Poster
$sql = "SELECT COUNT(*) FROM tblName WHERE type=\"minor\"";
$result = mysql_query($result);
$row = msql_fetch_row($result);
$number_of_minor_defects = $row[0];

$sql = "SELECT COUNT(*) FROM tblName WHERE type=\"major\"";
$result = mysql_query($result);
$row = msql_fetch_row($result);
$number_of_major_defects = $row[0];

print "Minor defects: ".$number_of_minor_defects."<br>Major defects: ".$number_of_major_defects;

Obviously alter the SQL code to suit your table structure and data. Also I have assumed that you have already initiated your mySQL connection.

edwinhermann 57 Junior Poster

Err, don't think the code Will posted is entirely right. You need:

substr($_REQUEST['cc_number'] , -4)

See http://www.php.net/substr for more info and examples.

edwinhermann 57 Junior Poster

hi experts,
always curious . why sometimes reference book use
simple quotation mark. sometime switch to double quotation mark. Does it matter in php?
e.g. define ('SQL_HOST','localahost');
however, in same define function i see double quotation in another source
define("CONSTANT", "Hello world.");

Thanks.

Most of the time it does not make a difference. For example:

$a = "Hello world.";

is the same as

$a = 'Hello world.';

One main difference is that you can embed variables in double quotes, but you cannot in single quotes. For example:

print "The variable contains $a right now.";

Using single quotes you have to concatenate like so

print 'The variable contains '.$a.' right now.';

Also, PHP will interpret more escape sequences for special characters when enclosed in double quotes.

Some coders like to stick to double quotes, others prefer to use single quotes. That's why you see differences in quote styles across different scripts.

For more information, see http://www.php.net/manual/en/language.types.string.php

edwinhermann 57 Junior Poster

I think you want this:

<?php
echo $this->_fetch_compile_include("includes/header.tpl", array('title' => $this->trigger_error("'lang' modifier does not exist", E_USER_NOTICE, __FILE__, __LINE__)));
?>

Second to last semi-colon was unnecessary.

edwinhermann 57 Junior Poster

The scope of ordinary variables outside a function remain outside that function. Conversely, the scope of ordinary variables inside a function remain inside that function.

In other words, you cannot declare a variable outside a function and use it inside a function, without using the global keyword.

So what you probably want to do is this:

<?php
$myVar1 = "Suzy";
$myVar2 = "Billy";

function getNames()
{
    global $myVar1;
    global $myVar2;

    $user1 = $myVar1;
    $user2 = $myvar2;

    return $user1 + $user2;
}
?>

The two extra lines I added tell the function that those variables are to be sourced from outside the function.

edwinhermann 57 Junior Poster

Where's the code?

edwinhermann 57 Junior Poster

Great, so that confirms the array structure of $players.

So in an earlier post I suggested the following:

Change the five SQL lines to this:

mysql_query("DELETE FROM buddies WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM inventoryitems WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM skills WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM keymap WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM characters WHERE characterid = ".$players['id']);

Did this work for you? If not, were error messages generated?

edwinhermann 57 Junior Poster

How are you determining whether it is missing the first few lines? Are you printing it out?

If the file contains certain escape characters, it can affect the print-out. For example, it may have CR instead of CRLF. Other escape sequences may trigger lines or characters not to show.

The first thing I would do to determine whether this is happening is to print out the length of the contents:

print strlen($contentsoffile);

and compare that to the size that the file system reports.

edwinhermann 57 Junior Poster

Did you try the code I posted (just before i-hate-blue)? If so, what were the results?
Also i-hate-blue has asked a question for which you haven't provided an answer yet.

edwinhermann 57 Junior Poster

What is stored in that array is ids and what i need to do is go into the table "buddies" and go to the row with that id and delete the entire row

You state you're getting errors. What exactly are the error messages?

I can take a guess at what you're trying to achieve:
Change the five SQL lines to this:

mysql_query("DELETE FROM buddies WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM inventoryitems WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM skills WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM keymap WHERE characterid = ".$players['id']);
mysql_query("DELETE FROM characters WHERE characterid = ".$players['id']);

I'll explain what this does:

Line 21 (in your original code listing) produces an array, with the indexes of the array being the names of the columns in your database. This array is stored in the variable $players.

Based on what you have in Line 18, the array with the key 'id' will be the ID of the player to delete.

Therefore, $players is what represents the ID of the player whose data is to be deleted.

The only thing I'm dubious about is your logic for determining which players should be purged (i.e. the WHERE clause in line 18). I don't know enough about your data to be able to say whether or not your logic is correct, but to check whether it's selecting the right players you can always insert a

print_r($players);

line after the while statement. That will show you a print out of …

edwinhermann 57 Junior Poster

The code should take the IDs and delete them from the tables but it isn't we are getting errors. Anyone see anything wrong?

In your code, $players is an array. You can't specify an array in your SQL string. So you need to reference the correct array element, such as:

mysql_query("DELETE FROM buddies WHERE characterid = $players['characterid']");

Also I noticed that line 25 has $result (which should also be $players).

edwinhermann 57 Junior Poster

Yeah, true I did notice it returned the 0-rated ones.

I ended up using:

SELECT * FROM table WHERE views >= (ROUND(views/1000,0) * 1000 - 100) AND views <= (ROUND(views/1000,0) * 1000 + 100) AND views > 100 ORDER BY views DESC

That would work, though I would have chosen AND (ROUND(views/1000,0)) > 0 as my condition.

Either or - it's just a matter of preference I guess.

edwinhermann 57 Junior Poster

I have a table in which each entry has a view counter. I would like to create a list that displays only entries that are within 100 views of a 1,000 view threshold. But, I want to also show each entry at any interval of 1,000 views. I.E., I would want to show all the following entries:

View Count:
975
1025
1980
2020
4960
5045
9990
10030
45980
46020
etc...

I am not quite sure the best way to do this, or if it is possible, in a MYSQL query.

I was thinking something along the lines of dividing each view count by 1000, and if the result is between x.95 - x.05 showing the row.

Any help on how to implement this, or a better solution, would be appreciated.

This should do it:

SELECT *,ROUND(views/1000,0) intervals FROM poll_questions WHERE views >= (ROUND(views/1000,0) * 1000 - 100) and views <= (ROUND(views/1000,0) * 1000 + 100) ORDER BY intervals ASC, views ASC

Here I've assumed "views" is the name of the column holding the views.

I have tested this code and it works.

edwinhermann 57 Junior Poster

Hello all,
I have a set of IF ELSE validation code ECHOING onto a php web page through a SWITCH staement. Everything works fine all error messages show up correctly. The problem is, after going through 3 conditons it starts to allow entry into my DB(mysql) all other entries goes straight through and stops validating.

Can someone help please it would be much appreciated, this has never happened to me before. is it common?

Thanks

After each header("Location:") command you need exit, otherwise the script keeps running.

E.g.:

if (empty($_POST[model]))
{                  		
  header("Location: " . $config_basedir . "/newcar.php?error=model"); 		     
  exit;
}
if (empty($_POST[engine]))
{                  		
  header("Location: " . $config_basedir . "/newcar.php?error=engine"); 		     
  exit;
}
if (empty($_POST[colour]))
{                  		
  header("Location: " . $config_basedir . "/newcar.php?error=colour"); 		     
  exit;
}
else {
  header("Location: " . $config_basedir . "/newcar.php?error=date");
  exit;
// etc. ......
edwinhermann 57 Junior Poster

Instead of

if(isset($result['GetSessionListResult']['diffgram']['NewDataSet']['Table']))

use

if (array_key_exists('table',$result['GetSessionListResult']['diffgram']['NewDataSet']))
edwinhermann 57 Junior Poster

thank you and another question the space is &nbsp; Do you know what code is for enter? Thank you very much

<br>

edwinhermann 57 Junior Poster
function validate_email($email)
{
    if (strlen($email) < 3) {
        return false;
    }
    if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,4})$/',$email)) {
        return false;
    } else {
        return $email;
    }
}

This code is close, but does not allow addresses ending in .museum or .travel.

That's because the code limits the TLD to have between 2 and 4 characters. I would suggest relaxing the rules a little and not impose an upper limit (i.e. only a minimum of 2 characters). Thus line 6 ought to be:

if (!preg_match('/^[_A-z0-9-]+((\.|\+)[_A-z0-9-]+)*@[A-z0-9-]+(\.[A-z0-9-]+)*(\.[A-z]{2,})$/',$email)) {
edwinhermann 57 Junior Poster

You have to replace $title with htmlspecialchars($title) when you output.

i.e.:

$more_button='  <input type="button" id="button_help1"  value="Summary" onClick="window.location=\'some_infos_research_en.php?title='.htmlspecialchars($title).'\'">
				<input type="button" id="button_help1"  value="Full description" onClick="window.location=\'upload/publications/en/'.$file.'\'">';
edwinhermann 57 Junior Poster

Hi,

my problem is in regular expression. I need to catch from html code hyperlink tag's href atribute content if this hyperlink contains search condition.

Here's what you want:

$a = "nail"; //search ctriteria between <a></a>
$s =<<<EOF
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&amp;module=1&amp;category=11" style="">  kaut kas cits </a>
<img> </img>
<br>
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&amp;module=1&amp;category=13" style="">  nails </a>
<a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&amp;module=1&amp;category=15" style="">  kaut kas cits2 </a>
EOF;
//this is how far i figured it out
$regexp = "/<a[^>]*href=\\\"([^\\\"]*)\\\"[^>]*>[^<]*".$a."[^<]*<\\/a>/miU";
//finding all hyperlinks
preg_match_all($regexp, $s, $matches);
// result must be 'index.php?item&amp;module=1&amp;category=13'
print_r($matches);

OUTPUT:

Array
(
    [0] => Array
        (
            [0] => <a class="level2" onmouseout="this.style.background = '';" onmouseover="this.style.background ='#2c7cf4';" href="index.php?item&amp;module=1&amp;category=13" style="">  nails </a>
        )

    [1] => Array
        (
            [0] => index.php?item&amp;module=1&amp;category=13
        )

)

You can then just read off the match(es) from $matches[1].

So, in other words, $matches[1][0] is your first match, $matches[1][1] is your second match (if it exists), $matches[1][2] is your third match (if it exists), and so on.

edwinhermann 57 Junior Poster

Sounds good - I use a similar system to send me a message when a particular radio station plays the same song twice in one day (first caller gets $1,000). The songs are posted on their web site.

Anyway, back to what you're doing: You could improve the cron side of things. Instead of using cron to call wget, which calls the PHP page (via a Web server), why not modify your PHP file like so:

#!/usr/bin/php
<?php

// your PHP code here

?>

Ensure the file has execute permissions (chmod 700 will work becase that gives you permissions to read, write and execute).

Then just have cron call that file instead of wget. (That file is effectively an executable script).

Note: You may need to change /usr/bin/php to match the path of wherever PHP happens to be installed on your server.

edwinhermann 57 Junior Poster

Session data holds whatever you want it to.

Client side, there's only a random token that can be "stolen" by hackers. Server side, while it's possible for them to steal your session data if they can break into the server you've probably got more to worry about. For example, they could read your php.ini file, or your config file and obtain the mySQL username and password. They they've got access to pretty much everything!

Normally you don't need to store the password. In fact, usually you'd only store the id of the row of the user. That's enough to identify the user, and for you to query the database for information based on that id number.

The super global $_SESSION is used to store session data that you need. For example, normally all you'd need to store is something like this:

$_SESSION["id_of_user"] = 123;

and when you need to query the database for information about the user, you'd refer back to that variable.

$sql = "SELECT * FROM users WHERE id = ".mysql_real_escape_string($_SESSION["id_of_user"]);
edwinhermann 57 Junior Poster

If it is XML output I would parse it using the xml parsing functions.

However, if it's not entirely XML (or not XML at all), then using preg_match_all should be fine. Here's some sample code to show you:

$b = <<<'ENDOFEXAMPLE'
<translate id="4" token_id="0" variant_id="1">contents............</translate>
blah blah blah
<translate id="9" token_id="8" variant_id="7">other contents...</translate>
ENDOFEXAMPLE;

preg_match_all("/<translate[^>]*\\ id=\\\"([^>]*)\\\"[^>]*\\ token_id=\\\"([^>])*\\\"[^>]*\\ variant_id=\\\"([^>])*\\\"[^>]*>([^<]*)<\\/translate>/imU",$b,$matches);

print_r($matches);

?>

that outputs:

/*
Array
(
    [0] => Array
        (
            [0] => <translate id="4" token_id="0" variant_id="1">contents............</translate>
            [1] => <translate id="9" token_id="8" variant_id="7">other contents...</translate>
        )

    [1] => Array
        (
            [0] => 4
            [1] => 9
        )

    [2] => Array
        (
            [0] => 0
            [1] => 8
        )

    [3] => Array
        (
            [0] => 1
            [1] => 7
        )

    [4] => Array
        (
            [0] => contents............
            [1] => other contents...
        )

)
*/

You can see that the output is an array. Starting at index 1, the contents of that array are:

index = 1: an array of ids
index = 2: an array of token_ids
index = 3: an array of variant_ids
index = 4: the contents of the <translate> tag

The way I've written it, the order of the attributes of the <translate> is fixed. In other words, id="" must come before token_id="" which in turn must come before variant_id="". There can be other attributes inserted in between, but the overall order must be as I've described.

If you don't know that the order will be like that, you'd have to run several preg_match_all …

edwinhermann 57 Junior Poster

A simpler way would be this single-line solution:

print 'There are '.preg_match_all('/[aeiou]/i',$_POST["fname"],$matches).' in the string ('.$_POST["fname"].')';
nav33n commented: Neat! :) +6
edwinhermann 57 Junior Poster

I can't quite tell whether this is the reason, but you need to ensure that not only are the permissions set on the end directory, but also (at minimum) execute permissions on all the parent directories required to traverse to that directory.

In other words, suppose I'm in /one/two/three and I want to write to /three/blind/mice, not only do I need to specify write permissions on "mice", but also a minimum of 111 permissions on "three" and "blind". Otherwise I can't navigate to "mice".

I would try setting 711 on all parent directories of the target directory.

edwinhermann 57 Junior Poster

Hi EggMatters,

To make your code work on either Windows or *nix platforms, use the constant PATH_SEPARATOR in place of a slash. For example:

$stuff = file_get_contents("some_dir". PATH_SEPARATOR."another_dir". PATH_SEPARATOR.$filename);

The constant PATH_SEPARATOR represents "/" on *nix systems and "\" on Windows systems.