Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

find content between 2 characters

Status
Not open for further replies.

fsqueeen

Programmer
Jul 8, 2002
43
MY
i had two variables called $phone and $url where

$phone = '600180320';

$url = "[phone:1-3]&mid3=[phone:4-6]&last3=[phone:7-9]";


first3=[phone:1-3] means that the first to third character in $phone will be assign to query string 'first3', and so forth for mid3 and last3.

Can anyone tell me how to get the 'phone', '1' and '3' in [phone:1-3]?

thanks!
 
i mean i wil hav to replace all those string after '=' (e.g. [phone:1-3], [phone:7-9]) with correspond data (e.g. 600, 320) in the $url.
 
Do you want a variable containing three variables?

first3=[phone:1-3]&mid3=[phone:4-6]&last3=[phone:7-9]";
Code:
echo "{$first3} {$mid3} {$last3}";

Olav Alexander Mjelde
Admin & Webmaster
 
hello DaButcher,

$phone = '600180320';

$url = "[phone:1-3]&mid3=[phone:4-6]&last3=[phone:7-9]";

i need the $url becomes

$url = "
To make [phone:4-6] becomes '180', i hav to get the 4th to 6th digits from variable 'phone'.

I juz wonder how to make the system find out all these pattern [] in $url, and then take out the content between [], in this case is 'phone:4-6', and then get the 4-6 digits from variable 'phone'.

thanks...
 
hi,
you have to use substr() function
Code:
<?php

$phone = '600180320';
$url = '[URL unfurl="true"]http://www.abc.com?first3='.substr($phone,[/URL] 0, 3).
        '&mid3='.substr($phone, 3, 3).
        '&last3='.substr($phone, 6, 3);
echo $url;
?>

___
____
 
btw. why do you need the phone in the querystring?

What is it that you wish to accomplish?
Putting things in the querystring, leaves it open to the subject of manipulation.

Olav Alexander Mjelde
Admin & Webmaster
 
hello DaButcher...

thanks for the advise, i know it's unsafe to place things in querystring, but it's unavoidable in this system..

anyway, i had found the solution for this question. i using 'explode' to take out the variable $phone, and the digits as well. Everything goes well. thanks for the suggestion above!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top