Using PHP to find a word and then capture data which follows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tqualizerstore
Forum Newbie
Posts: 1
Joined: Sat Nov 01, 2008 12:28 pm

Using PHP to find a word and then capture data which follows

Post by tqualizerstore »

Hi everyone,

I am trying to construct some PHP which can search for a specific word within a bit of chunk of data which I am calling using this code:

<?php
include "./auth.php";
x_load("order");
$order_data = func_select_order(Order Number goes Here);
echo $order_data["details"];
?>

That code basically calls up credit card details of Customer X which is as far as I've gotten.

The next step is to take that data and search for the word "{CardNumber}:" and then capture the first six digits which come immediately after. I then need to be able to take those six digits and pass them into a string of an <a href=""> call that comes later in the page.

I'm completely lost though...any ideas?
zephyr750
Forum Newbie
Posts: 6
Joined: Sat Nov 01, 2008 8:05 am

Re: Using PHP to find a word and then capture data which follows

Post by zephyr750 »

I use the following to strip unique tags out of xml strings. maybe you could adapt it to your needs:

Code: Select all

 
function getTag($tag_name, $contents)
{
            $start_tag = "<" . $tag_name . ">";
            $end_tag = "</" . $tag_name . ">";
 
            $start_tag = "<" . $tag_name . ">";
            $end_tag = "</" . $tag_name . ">";
 
            // explode at opening tag
            $ex_content = explode($start_tag, $contents);
 
            
            // explode at closing tag
            $ex2_content = explode($end_tag, $ex_content[1]);
 
            // get the bit in the middle
            $tag = $ex2_content[0];
 
            return $tag;
 }
 
$the_bit_i_want = getTag({tag_text}, {string});
 
 
using something like - $the_bit_i_want = getTag({tag_text}, {string});

Hope this helps....
mmj
Forum Contributor
Posts: 118
Joined: Fri Oct 31, 2008 4:00 pm

Re: Using PHP to find a word and then capture data which follows

Post by mmj »

Code: Select all

$cardno = substr($order_data["details"], strpos('{CardNumber}:'), 6);
Post Reply