Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.