Sponsored Content
Full Discussion: Need Help with PHP REGEX
Top Forums Shell Programming and Scripting Need Help with PHP REGEX Post 302395388 by o0110o on Tuesday 16th of February 2010 12:43:07 AM
Old 02-16-2010
Need Help with PHP REGEX

Hello, I have this script:
Code:
<?php

function getLocation() {
$ip = $_SERVER['REMOTE_ADDR'];
$geo = file_get_contents("http://api.hostip.info/get_html.php?ip=$ip");
$results = urlencode($geo);
echo $results;
}

getLocation();

?>

Which returns:
Code:
Country%3A+CANADA+%28CA%29%0ACity%3A+ST.+JOHN%27S%2C+NL%0AIP%3A+142.162.13.207%0A

I would like for $results to contain only "ST.+JOHN%27S%2C+NL"; in other words the city name and the province/state for the visiting user.

What I'm aiming to do is make the regex change after this line:
Code:
$geo = file_get_contents("http://api.hostip.info/get_html.php?ip=$ip");

and before this line:
Code:
$results = urlencode($geo);

This way the modified data (ie. "City%2C+State") gets passed off into $results.
I need $results encoded because this script is going to be part of another script where $results get passed off as part of a URL parameter.

Regex seems to work differently with PHP, and I don't have much experience with regex or arrays; I'm just learning as I go Smilie
Any help would be greatly appreciated. Thanks Smilie

Last edited by o0110o; 02-16-2010 at 02:26 AM.. Reason: Additional Information
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regex

Hello I need to make a regex. I have a file myfile, in this file I want to find a number situated after PAYSLOT= Before PAYSLOT is the begining of line (I guess ^) and after the number is the end of line (I guess $) . I want to echo this number (I guess $1) and put it in my variable payslot.... (5 Replies)
Discussion started by: pppswing
5 Replies

2. Shell Programming and Scripting

regex help

I would like to search strings composed by only one type of charachter for example only strings composed by the charachter 'b' is it right? $egrep '\<(b+)+\>' filename Could be there some side effects? Regards. (1 Reply)
Discussion started by: and77
1 Replies

3. Shell Programming and Scripting

REGEX help

Hi Guys, I'm trying to write a script that will strip out a session id from an html webpage. I am missing something on the regex for parsing a variable. I am trying to get just the alpha-numeric value for scriptSessionId from this text: <script type="text/javascript">if(!JAWR){var JAWR =... (2 Replies)
Discussion started by: tank126
2 Replies

4. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

5. UNIX for Advanced & Expert Users

Vi Regex help

Can someone tell me what is going with this expression :%s/<C-V><C-M>/. Is there a way to get a more useful message if the carriage return has been deleted? http://objectmix.com/editors/149245-fixing-dos-line-endings-within-vim.html#post516826 Why does this expression work for... (1 Reply)
Discussion started by: cokedude
1 Replies

6. Shell Programming and Scripting

regex

hello, i'm quite new to regex and Perl in general. What i need is a regex that does this trasformatiuon: input : S45020:97,0; S45020:45,1; output : crrout:97; errout:45; there are some other combination but they're useless for the comprehension of the regex i need I need it for some... (2 Replies)
Discussion started by: perdidohate
2 Replies

7. UNIX for Dummies Questions & Answers

read regex from ID file, print regex and line below from source file

I have a file of protein sequences with headers (my source file). Based on a list of IDs (which are included in some of the headers), I'd like to print out only the specified sequences, with only the ID as header. In other words, I'd like to search source.txt for the terms in IDs.txt, and print... (3 Replies)
Discussion started by: pathunkathunk
3 Replies

8. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

9. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

10. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 02:01 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy