Jump to content

[SOLVED] Find what character is at what position


blufish

Recommended Posts

Hey guys, I need to know how to find what character is at a certain position, like

 

If I told php I wanted to know what the 4th character in a string which was "hello world!" It would output "l" anybody know how to do this or something like this?  any help is greatly appreciated.

it doesn't seem to be working, here is the code I have been making:

 

<?php
$code = $_POST['code'];
$leng = strlen($code);
$ncode = "<script type='text/javascript'>";
while($leng>0)
{
$ncode = $ncode."var a".$leng." = ".substr($ncode, $leng).";";
$leng = $leng-1;
}
$ncode = $ncode."</script>";
echo $ncode;
?>

 

...Trying to make my own script confuzzler :)...

 

To explain what it's supposed to do,

 

It's supposed to make a javascript which defines a bunch of variables based on the position of characters in the string.

 

I also tried this, It doesn't work:

<?php
$code = $_POST['code'];
$leng = strlen($code);
$ncode = "<script type='text/javascript'>";
while($leng>0)
{
$ncode = $ncode."var a".$leng." = ".$code[$leng].";";
$leng = $leng-1;
}
$ncode = $ncode."</script>";
echo $ncode;
?>

When I run your code:

<?php
$code = "this is a test";
$leng = strlen($code);
$ncode = "<script type='text/javascript'>\n";
while($leng>0)
{
$ncode = $ncode."var a".$leng." = ".$code[$leng].";\n";
$leng = $leng-1;
}
$ncode = $ncode."</script>";
echo $ncode;
?>

I get

<script type='text/javascript'>
var a14 = ;
var a13 = t;
var a12 = s;
var a11 = e;
var a10 = t;
var a9 =  ;
var a8 = a;
var a7 =  ;
var a6 = s;
var a5 = i;
var a4 =  ;
var a3 = s;
var a2 = i;
var a1 = h;
</script>

What am I supposed to be seeing?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.