Page 1 of 2
Reading parts of a posted variable
Posted: Sun Aug 13, 2006 10:05 pm
by tristanlee85
I'm using $_POST to send form information to another page. An example of what might be received using:
Code: Select all
$destination = $_POST['dest_name'];
could output something like
422 (Syracuse)
What I would like to do is store the first 3 numbers in their own variable. In this case, since $destination echos
422 (Syracuse), how can I stript off the first 3 numbers so I can make a vairable $dest_num echo
422?
Posted: Sun Aug 13, 2006 10:11 pm
by feyd
Read up on regular expressions (the Regex board) .. or maybe use
explode().
Posted: Sun Aug 13, 2006 10:27 pm
by RobertGonzalez
If you know it will always be three numbers, try
substr().
Posted: Sun Aug 13, 2006 11:24 pm
by tristanlee85
Worked perfect. Thank you!
Posted: Fri Oct 13, 2006 6:42 pm
by tristanlee85
I'll bring this back since I have a similar question. In phpBB, when you insert information in the signature, it's hashed within the BBcode. For example, if I were to insert an image in my signature, it would say something like
Code: Select all
[img:a86d1f200f]some_image.jpg[/img:a86d1f200f]
What I'm wanting to do is search through the whole signature that is pulled from the database. In other words, this may by my signature code stored in MySQL for phpBB:
Code: Select all
PlastikRacing Owner
[img:a86d1f200f]some_image.jpg[/img:a86d1f200f]
[b:44f2b8ecdc]Image and Video Hosting[/b:44f2b8ecdc]
http://www.plastikhosting.net
What I would like to do is search through the signature and if there is a image inserted using the [IMG] tags, pull it out into it's own variable, kind of like explode(). With this function, the output would be something like:
Code: Select all
$sig[0] = "[img]some_image.jpg[/img]";
$sig[1] = "PlastikRacing Owner" . $sig[0] . "[b]Image and Video Hosting[/b]
http://www.plastikhosting.net";
Maybe I'm going about this the wrong way, but is this possible, or is there an easier way?
Posted: Fri Oct 13, 2006 7:01 pm
by RobertGonzalez
Posted: Fri Oct 13, 2006 7:07 pm
by tristanlee85
And use preg_match_all()?
Posted: Fri Oct 13, 2006 7:08 pm
by RobertGonzalez
Posted: Fri Oct 13, 2006 7:41 pm
by tristanlee85
Alright. I'm a little confused as to how it works. How do I distinguish between:
and
and
within the signature?
Posted: Fri Oct 13, 2006 7:43 pm
by feyd
In the most basic, but with its own caveats:
Posted: Fri Oct 13, 2006 8:29 pm
by tristanlee85
Alright, so is there any way for me to echo out what is being matched or not? I'm not having any luck here.
Code: Select all
preg_match('#\[(img:[^\]]+)\](.+?)\[/\\1\]#',$user_sig,$matches);
echo $matches[0];
All I'm trying to do is take the user's signature,
$user_sig, and remove any
Code: Select all
[img:xxxxxxxxxx]http://www.website.com/image.jpg[/img:xxxxxxxxxx]
from it, and then store is back as
$user_sig.
Posted: Fri Oct 13, 2006 9:38 pm
by n00b Saibot
try changing regex to following:
Code: Select all
preg_match('#\[(img:[^\]]+)\](.+?)\[/\\1\]#is',$user_sig,$matches);
Posted: Fri Oct 13, 2006 9:51 pm
by tristanlee85
Does $matches store the array of what is matched? I think I'm trying to make this more complicated than what it is, or I'm trying to do it the wrong way. Like I stated before, I would like to read
$user_sig. If there is anything such as
Code: Select all
[img:xxxxxxxxxx]http://www.website.com/image.gif[/img:xxxxxxxxxx]
within
$user_sig, I want to remove it.
If
$user_sig =
Code: Select all
PlastikRacing Owner
[img:a86d1f200f]some_image.jpg[/img:a86d1f200f]
[b:44f2b8ecdc]Image and Video Hosting[/b:44f2b8ecdc]
http://www.plastikhosting.net
remove the image so
$user_sig =
Code: Select all
PlastikRacing Owner
[b:44f2b8ecdc]Image and Video Hosting[/b:44f2b8ecdc]
http://www.plastikhosting.net
Posted: Fri Oct 13, 2006 10:11 pm
by n00b Saibot
Posted: Fri Oct 13, 2006 10:28 pm
by tristanlee85
I'm making a little bit of progress. I've read over the preg_ functions on PHP.net, but exactly how do you determine something such as
How about this: with the preg_replace, how could I search for
Code: Select all
<img src="http://www.website.com/images.jpg" alt="Image" title="Image" border="0" />
instead of what I had posted before
Code: Select all
[img:a86d1f200f]some_image.jpg[/img:a86d1f200f]