Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

Get words between 2 chars

I've no expierence in doing this and i do not know how to google.

Example:

https://hackforums.net


get the chars between http:// and .net
so the output is hackforums

how would i do this?
You would explode the string.
PHP Code

<?php 
$str 
= explode('http://', 'https://hackforums.net');
printf($str); 
http://stackoverflow.com/questions/56964...trings-php

(Mar 1, 2014 10:44 AM)z0tpyrk Wrote:  i do not know how to google.

You could literally type in the title of your thread into Google and get the answer. Prepend or append php to it and you've got an even better answer. At least put in a little effort.
still lurkin. still bitcoin cashin.
if you only need to parse a url, use parse_url.
PHP Code

<?php 
$u 
= parse_url('https://hackforums.net');
var_dump($u); 
(Mar 1, 2014 01:27 PM)badbrains Wrote:  if you only need to parse a url, use parse_url.
PHP Code

<?php 
$u 
= parse_url('https://hackforums.net');
var_dump($u); 

Good example for urls Wolf.

I know several other more efficient ways to get text "between 2 chars", like Orgy and others have mentioned above but
here's a PHP beginners example. Much longer than other methods but I'm posting it just for OP learning purposes.

PHP Code

<?php
$content 
= '<html><title>Hello World</title></html>';

$search  = '<title>';
$start = strpos($content, $search) + strlen($search);
$stop = strpos($content, '</title>', $start);
$length = ($stop - $start);
$result = substr($content, $start, $length);
echo 
$result;
?>
| Cheap Custom Coding | 15+ Years | Linux or Windows | C, C++, C#, PERL, PHP, VB | PM Me For Quotes |
My 2 cents
PHP Code

<?php 
preg_match
('/http:\/\/(.*)\.net/','https://hackforums.net',$n);
echo 
$n[1]; 
(Mar 1, 2014 01:52 PM)RedWaters Wrote:  My 2 cents
PHP Code

<?php 
preg_match
('/http:\/\/(.*)\.net/','https://hackforums.net',$n);
echo 
$n[1]; 

Eww, RegEx. @OP, are you trying to use this on URL's only or just anything else?


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by JASDec 30, 2017 02:44 PM 5 115 Dec 30, 2017 02:44 PM
Last Post: Prof. Farnsworth
[PHP] by chrisnAug 14, 2014 01:04 PM 5 203 Aug 14, 2014 01:04 PM
Last Post: chrisn
[PHP] by Toph BeifongApr 27, 2012 03:27 PM 7 101 Apr 27, 2012 03:27 PM
Last Post: Eight