immanuelx2
-
Posts
96 -
Joined
-
Last visited
Never
Posts posted by immanuelx2
-
-
Fellow PHP Coders,
I am working on a blogging system that will involve the use of images. Most images will be fairly large so thumbnails are a must.
Is there too much overhead to dynamically generate the thumbnails on-the-fly, each page load, or should the thumbnails be generated once upon upload and then saved as a separate file.
The reason I ask is because there will be times when I'd like thumbnails to be bigger than others (headline stories).
Thanks in advance for all input!
-
site.com/news/ does not work
I deliberately left this out so you can test the dynamic rule
Now you just need the default ive changed it so it wont conflict with any other rule.
#default for all sections -> http://site.com/type=news or http://site.com/type=forum
RewriteRule ^type=(.*) index.php?type=$1 [L,QSA]
I see... so no way to make it ^(.*)/ because it's the root and it can't be dynamic?
I have to do ^news/, and any other sections, explicitly correct?
-
Thanks. I realized I wasn't calling the damn functions right forgot the trailing ()
-
For example:
class Post { function __construct() {} function getRelatedPosts() { // get related posts through query while ($post = mysql_fetch_assoc($query)) { $post = new Post(); $post->getTitle; } } }
Reason I ask is that I am having trouble getting it to output anything using the getRelated type function.
Or is there a better way of trying to accomplish something like this?
-
No. Because your fake urls wont exist
news/category/id-title will have to be real eg: news/category/id-title/index.php
OK clear your htaccess file and add just this:
Options +FollowSymlinks RewriteEngine on RewriteRule ^news/(.*)/(.*) index.php?type=news&category=$1&id=$2 [L,QSA]
Your url will be :
site.com/news/cat/
or
site.com/news/cat/3
or
site.com/news/anothercat/
or
site.com/news/catanothercat/5
Let me know how it went
Hmm...
site.com/news/ does not work
site.com/news/cat/ works
site.com/news/cat/12053-the-article-title works
Is there a separate line I should add for just site.com/news/ to work?
-
What if I can get the entire string (eg. "news/category/id-title") through a $_GET[] variable and just parse it via explode() in PHP?
That way PHP can handle all the redirecting... is this possible?
-
Didn't work
So how come some sites can have rewrites for /news, /news/category and even /news/category/articleid ??
-
Yes. You can also simplify it resulting in a lot less work and lines
#default news page -> http://www.site.com/news/ RewriteRule ^news/$ index.php?type=news #working news section -> http://www.site.com/news/cat1/ OR http://www.site.com/news/cat1/3 RewriteRule ^news/(.*?)/([0-9]+)-(.*?)$ index.php?type=news&category=$1&id=$2
Hmm.. It appears as though only the website/news/ works... if I add category or id ( website/news/category/ ) it says page does not exist..
Also, if the url is website/news instead of website/news/ (with the ending slash), it doesn't work.
-
You have 3 dynamic rules with no write stops [L,QSA] so its gonna keep writing into your next rule
You can still have it like you had but use anchors
RewriteRule ^(.*?)$ index.php?type=$1
RewriteRule ^Anchor_name_(.*?)/(.*?) index.php?type=$1&category=$2
RewriteRule ^Another_anchor_/(.*?)/([0-9]+)-(.*?)$ index.php?type=$1&category=$2&articleid=$3
If you dont have write rules you cant have 3 dynamic roots
RewriteRule ^ DYNAMIC ROOT --> (.*?)$ index.php?type=$1
RewriteRule ^ DYNAMIC ROOT --> (.*?)/(.*?) index.php?type=$1&category=$2
RewriteRule ^ DYNAMIC ROOT --> (.*?)/(.*?)/([0-9]+)-(.*?)$ index.php?type=$1&category=$2&articleid=$3
I think I'm starting to understand...
So you are saying I need something like this:
RewriteRule ^news/$ index.php?type=news
RewriteRule ^news/(.*?) index.php?type=news&category=$2
RewriteRule ^news/(.*?)/([0-9]+)-(.*?)$ index.php?type=news&category=$2&id=$3
RewriteRule ^forum/$ index.php?type=forum
RewriteRule ^forum/(.*?) index.php?type=forum&category=$2
RewriteRule ^forum/(.*?)/([0-9]+)-(.*?)$ index.php?type=forum&category=$2&id=$3
Is that correct?
-
Set your default type
RewriteRule ^(.*)$ index.php?type=default_name
Depending on your interface you need a anchor
RewriteRule ^News/(.*?) index.php?type=News&category=$1
Otherwise it can be dynamic based on the hyperlink, but this can cause issues with your article id rule
RewriteRule ^(.*?)/(.*?) index.php?type=$1&category=$2
This needs an anchor if you use the above dynamic rule
RewriteRule ^News/(.*?)/([0-9]+)-(.*?)$ index.php?type=News&category=$1&articleid=$2
Thanks for the reply.
I'm a bit confused on what you mean by interface and anchor.. Could you briefly explain those for me please?
-
Currently, I have:
RewriteEngine on # Turn http://mydomain.com into http://www.mydomain.com/ RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC] RewriteRule ^(.*)$ http://www.mydomain.com/$1 [N,R=301] RewriteRule ^(.*?)/(.*?)/([0-9]+)-(.*?)$ index.php?type=$1&category=$2&articleid=$3&name=$4
An example page would be:
http://www.mydomain.com/news/category/12345-this-is-the-article/
So if someone pointed to http://www.mydomain.com/news it should take them to index.php?type=news
Or if someone pointed to http://www.mydomain.com/news/hardware it should take them to index.php?type=news&category=hardware
How should I set up my other Rewrite rules? I'm thinking of some sort of hierarchy/tree structure like:
RewriteRule ^(.*?)$ index.php?type=$1 RewriteRule ^(.*?)/(.*?) index.php?type=$1&category=$2 RewriteRule ^(.*?)/(.*?)/([0-9]+)-(.*?)$ index.php?type=$1&category=$2&articleid=$3
..But I'm not sure if that would work or if I'm even on the right track.
Any help is greatly appreciated!
-
$string = str_replace(' ','-',$string); // replace all spaces with hyphen $string = preg_replace('~[^-a-z0-9]+~i','',$string); // remove anything not alphanumeric or hyphen with $string = strtolower($string); // make it lowercase? (that's what you have in your from -> to example
As far as changing for instance "Numb3rs" to "numbers" (changing the 3 to an e) that's a bit more complex. Think it would be practically impossible to transform arbitrary text like that. I suppose you can catch most of those by first exploding at a space (or dash, if you have it post-str_replace), then loop through each element and check to see if it's a combo of words and letters (to avoid changing for instance 333 to eee), and if so, loop through each letter and check against an array containing "3" => 'e', "0" => 'o', etc... and replace if found. But that's not going to be perfect, as you will end up changing 3rd to erd, sort of thing. you could further have a list of exceptions, like number, followed by st,nd,rd,th I guess.
Thanks a lot for the example.
Actually, that Numb3rs to numbers was an error on my part lol.. I just wanted to include a number to allow them in the output as well, but I forgot to put the 3 in the output!!
Thanks again!!
-
Hi all.
I am looking to generate SEO-url-friendly titles.
I'm guessing some sort of preg_replace function will be able to get the job done. Unfortunately I'm still a beginner with regular expressions.\
I'm looking to do something like the following:
from:
This Is a Great Article Title; With 'Quotes,' Numb3rs, commas, and Semicolons
to:
this-is-a-great-article-title-with-quotes-numbers-commas-and-semicolons
Basically strip out EVERYTHING except for numbers and letters, and replace the spaces with dashes. Is this possible?
Thanks in advance.
-
Thanks. Handy website, although I am very new to Regexp.
If someone could provide me with an example that could strip out any special characters and just leave letters, numbers, and dashes in place of spaces I will give you a cookie
Or should I post this in the Regexp subforum?
-
Hey guys.
I'm trying to get my site SEO-ready and have got the mod rewrite in the works, but I was wondering what the best way is to construct an SEO URL-friendly article title. I was thinking the PHP could handle this and store it in the database.
Example:
This Is a Great Article Title; With 'Quotes' and Semicolons
to
this-is-a-great-article-title-with-quotes-and-semicolons
I'm thinking some sort of preg_replace or str_replace functions might do the job?
Thanks in advance
-
what you are looking to do is called "pagination"
I would google "php pagination" there should be a tutorial somewhere out there (maybe even on here?)
-
So ENUM is just for restrictions. Say you have a field for months. You can use ENUM to only allow the list you provide. For example:
Table date
month ENUM('Jan', 'Feb', 'Mar' ...);
I didn't bother listing all 12 months, but you get the idea. So with ENUM, you can prevent entries like 1 or January because they don't match any of the ones in your list. Just use ENUM when you have a fixed array of possible values. It's just so you know that field can only have one of those values. Just added restrictions.
Now for your vehicle enumeration, you can use ENUM('Car', 'Trunk', 'SUV') however I would suggest you put them into another table. Up to you really.
Hope this clears it up a bit.
Thanks, this does clear up quite a bit.
So all enum does is restrict a table to the values you specify.
Wouldn't it be more efficient to store integers as representations of the enumerations (1-3), and have PHP parse them out(Car, Truck SUV)?
-
bump.
I suppose my question is why I would use MySQL enums when I could use PHP to handle those, and at the same time, how are MySQL enum values stored and manipulated?
-
This might be a very noobish question, but I have always wondered how the mysql ENUM type works.
I understand the enumeration concept( I think)
Vehicle enumeration:
1=>Car 2=>Truck 3=>SUV
So my question is, using that above scenario, how (or better yet why) would I use the Mysql ENUM type to store that. Why not just store them as '1', '2' or '3' and let the PHP figure out what those enumerations stand for?
Thanks in advance
-
SELECT * FROM table
WHERE tag != 'tag1' AND tag != 'tag2' AND tag != 'tag3' AND tag != 'tag4' AND tag != 'tag5'
Can i do something like..
WHERE tag NOT IN ('tag1','tag2','tag3','tag4','tag5') ?
-
Sorry, let me add that the contents originate from an HTML textarea and are then stored in a MySQL text field.
-
Hi all.
Quick run down:
Basically, I have a comment system on my website that has the ability to quote other peoples comments and reply to them (much like on these forums).
Now the problem is that a lot of people like to hit the enter button after quoting somebody, to separate the quote from their own text, example:
[quote]quote text[/quote] reply text
The problem is that by quote BBcode (seen above) is converted to a div block element on output, and therefore line breaks are added before and after the block quote.
Here is my question: How can I remove the extra newline (since I use nl2br() to convert it to breaks) after the quote?
The following does not work:
<?php $comment = str_replace("[/quote]\n","[/quote]",$comment); // no worky preg_replace('@\[/quote\]\\n@si', '[/quote]',$comment); // no worky
Help is much appreciated!
-
what about trim()
what a great idea!!!
-
Hey guys,
I have a form that is being processed via $_POST variables and was wondering if there is a regexp way of removing a newline char (\n) if it is the very last thing that was inside a textarea.
Also, any idea why this isn't working?
<?php $comment = str_replace("[/quote]\n","[/quote]",$comment); ?>
Thanks in advance!
Dilemma - Image handling (thumbnails)
in PHP Coding Help
Posted
Thanks for the responses guys, really helpful.
I suppose I will have to carefully plan and figure out which size thumbnails I will need in advance.
Staying on topic, do you guys have any links to any good public PHP image handling / manipulation classes? Or perhaps any batch-processing thumbnail creation techniques
Thanks again